github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/query/do_tx_options.go (about) 1 package query 2 3 import ( 4 "github.com/ydb-platform/ydb-go-sdk/v3/retry" 5 "github.com/ydb-platform/ydb-go-sdk/v3/trace" 6 ) 7 8 var ( 9 _ DoTxOption = idempotentOption{} 10 _ DoTxOption = traceOption{} 11 ) 12 13 func (idempotentOption) applyDoTxOption(opts *DoTxOptions) { 14 opts.Idempotent = true 15 opts.RetryOptions = append(opts.RetryOptions, retry.WithIdempotent(true)) 16 } 17 18 func (opt traceOption) applyDoTxOption(o *DoTxOptions) { 19 o.Trace = o.Trace.Compose(opt.t) 20 } 21 22 var _ DoTxOption = doTxSettingsOption{} 23 24 type doTxSettingsOption struct { 25 txSettings TransactionSettings 26 } 27 28 func (opt doTxSettingsOption) applyDoTxOption(opts *DoTxOptions) { 29 opts.TxSettings = opt.txSettings 30 } 31 32 func WithTxSettings(txSettings TransactionSettings) doTxSettingsOption { 33 return doTxSettingsOption{txSettings: txSettings} 34 } 35 36 func NewDoTxOptions(opts ...DoTxOption) (doTxOptions DoTxOptions) { 37 doTxOptions.TxSettings = TxSettings(WithDefaultTxMode()) 38 doTxOptions.Trace = &trace.Query{} 39 40 for _, opt := range opts { 41 opt.applyDoTxOption(&doTxOptions) 42 } 43 44 return doTxOptions 45 }