99 querySerializableReadWrite = & Ydb_Query.TransactionSettings_SerializableReadWrite {
1010 SerializableReadWrite : & Ydb_Query.SerializableModeSettings {},
1111 }
12+ querySerializableReadWriteTxSelector = & Ydb_Query.TransactionControl_BeginTx {
13+ BeginTx : & Ydb_Query.TransactionSettings {
14+ TxMode : querySerializableReadWrite ,
15+ },
16+ }
1217 queryStaleReadOnly = & Ydb_Query.TransactionSettings_StaleReadOnly {
1318 StaleReadOnly : & Ydb_Query.StaleModeSettings {},
1419 }
20+ queryStaleReadOnlyTxSelector = & Ydb_Query.TransactionControl_BeginTx {
21+ BeginTx : & Ydb_Query.TransactionSettings {
22+ TxMode : queryStaleReadOnly ,
23+ },
24+ }
1525 querySnapshotReadOnly = & Ydb_Query.TransactionSettings_SnapshotReadOnly {
1626 SnapshotReadOnly : & Ydb_Query.SnapshotModeSettings {},
1727 }
28+ querySnapshotReadOnlyTxSelector = & Ydb_Query.TransactionControl_BeginTx {
29+ BeginTx : & Ydb_Query.TransactionSettings {
30+ TxMode : querySnapshotReadOnly ,
31+ },
32+ }
1833 queryOnlineReadOnlyAllowInconsistentReads = & Ydb_Query.TransactionSettings_OnlineReadOnly {
1934 OnlineReadOnly : & Ydb_Query.OnlineModeSettings {AllowInconsistentReads : true },
2035 }
36+ queryOnlineReadOnlyAllowInconsistentReadsTxSelector = & Ydb_Query.TransactionControl_BeginTx {
37+ BeginTx : & Ydb_Query.TransactionSettings {
38+ TxMode : queryOnlineReadOnlyAllowInconsistentReads ,
39+ },
40+ }
2141 queryOnlineReadOnlyForbidInconsistentReads = & Ydb_Query.TransactionSettings_OnlineReadOnly {
2242 OnlineReadOnly : & Ydb_Query.OnlineModeSettings {AllowInconsistentReads : false },
2343 }
44+ queryOnlineReadOnlyForbidInconsistentReadsTxSelector = & Ydb_Query.TransactionControl_BeginTx {
45+ BeginTx : & Ydb_Query.TransactionSettings {
46+ TxMode : queryOnlineReadOnlyForbidInconsistentReads ,
47+ },
48+ }
2449 tableSerializableReadWrite = & Ydb_Table.TransactionSettings_SerializableReadWrite {
2550 SerializableReadWrite : & Ydb_Table.SerializableModeSettings {},
2651 }
52+ tableSerializableReadWriteTxSelector = & Ydb_Table.TransactionControl_BeginTx {
53+ BeginTx : & Ydb_Table.TransactionSettings {
54+ TxMode : tableSerializableReadWrite ,
55+ },
56+ }
2757 tableStaleReadOnly = & Ydb_Table.TransactionSettings_StaleReadOnly {
2858 StaleReadOnly : & Ydb_Table.StaleModeSettings {},
2959 }
60+ tableStaleReadOnlyTxSelector = & Ydb_Table.TransactionControl_BeginTx {
61+ BeginTx : & Ydb_Table.TransactionSettings {
62+ TxMode : tableStaleReadOnly ,
63+ },
64+ }
3065 tableSnapshotReadOnly = & Ydb_Table.TransactionSettings_SnapshotReadOnly {
3166 SnapshotReadOnly : & Ydb_Table.SnapshotModeSettings {},
3267 }
68+ tableSnapshotReadOnlyTxSelector = & Ydb_Table.TransactionControl_BeginTx {
69+ BeginTx : & Ydb_Table.TransactionSettings {
70+ TxMode : tableSnapshotReadOnly ,
71+ },
72+ }
3373 tableOnlineReadOnlyAllowInconsistentReads = & Ydb_Table.TransactionSettings_OnlineReadOnly {
3474 OnlineReadOnly : & Ydb_Table.OnlineModeSettings {AllowInconsistentReads : true },
3575 }
76+ tableOnlineReadOnlyAllowInconsistentReadsTxSelector = & Ydb_Table.TransactionControl_BeginTx {
77+ BeginTx : & Ydb_Table.TransactionSettings {
78+ TxMode : tableOnlineReadOnlyAllowInconsistentReads ,
79+ },
80+ }
3681 tableOnlineReadOnlyForbidInconsistentReads = & Ydb_Table.TransactionSettings_OnlineReadOnly {
3782 OnlineReadOnly : & Ydb_Table.OnlineModeSettings {AllowInconsistentReads : false },
3883 }
84+ tableOnlineReadOnlyForbidInconsistentReadsTxSelector = & Ydb_Table.TransactionControl_BeginTx {
85+ BeginTx : & Ydb_Table.TransactionSettings {
86+ TxMode : tableOnlineReadOnlyForbidInconsistentReads ,
87+ },
88+ }
3989)
4090
4191// Transaction settings options
@@ -44,10 +94,45 @@ type (
4494 ApplyQueryTxSettingsOption (txSettings * Ydb_Query.TransactionSettings )
4595 ApplyTableTxSettingsOption (txSettings * Ydb_Table.TransactionSettings )
4696 }
47- Settings []SettingsOption
97+ Settings interface {
98+ ControlOption
99+ Selector
100+
101+ ToTableSettings () * Ydb_Table.TransactionSettings
102+ ToQuerySettings () * Ydb_Query.TransactionSettings
103+ }
104+ Options []SettingsOption
48105)
49106
50- func (opts Settings ) applyTableTxSelector (txControl * Ydb_Table.TransactionControl ) {
107+ func (opts Options ) applyTxControlOption (txControl * Control ) {
108+ txControl .selector = BeginTx (opts ... )
109+ }
110+
111+ func (opts Options ) ToTableSettings () * Ydb_Table.TransactionSettings {
112+ txSettings := & Ydb_Table.TransactionSettings {}
113+ for _ , opt := range opts {
114+ if opt != nil {
115+ opt .ApplyTableTxSettingsOption (txSettings )
116+ }
117+ }
118+
119+ return txSettings
120+ }
121+
122+ func (opts Options ) ToQuerySettings () * Ydb_Query.TransactionSettings {
123+ txSettings := & Ydb_Query.TransactionSettings {}
124+ for _ , opt := range opts {
125+ if opt != nil {
126+ opt .ApplyQueryTxSettingsOption (txSettings )
127+ }
128+ }
129+
130+ return txSettings
131+ }
132+
133+ var _ Settings = Options (nil )
134+
135+ func (opts Options ) applyTableTxSelector (txControl * Ydb_Table.TransactionControl ) {
51136 beginTx := & Ydb_Table.TransactionControl_BeginTx {
52137 BeginTx : & Ydb_Table.TransactionSettings {},
53138 }
@@ -59,7 +144,7 @@ func (opts Settings) applyTableTxSelector(txControl *Ydb_Table.TransactionContro
59144 txControl .TxSelector = beginTx
60145}
61146
62- func (opts Settings ) applyQueryTxSelector (txControl * Ydb_Query.TransactionControl ) {
147+ func (opts Options ) applyQueryTxSelector (txControl * Ydb_Query.TransactionControl ) {
63148 beginTx := & Ydb_Query.TransactionControl_BeginTx {
64149 BeginTx : & Ydb_Query.TransactionSettings {},
65150 }
@@ -71,7 +156,7 @@ func (opts Settings) applyQueryTxSelector(txControl *Ydb_Query.TransactionContro
71156 txControl .TxSelector = beginTx
72157}
73158
74- func (opts Settings ) ToYdbQuerySettings () * Ydb_Query.TransactionSettings {
159+ func (opts Options ) ToYdbQuerySettings () * Ydb_Query.TransactionSettings {
75160 txSettings := & Ydb_Query.TransactionSettings {}
76161 for _ , opt := range opts {
77162 if opt != nil {
@@ -82,7 +167,7 @@ func (opts Settings) ToYdbQuerySettings() *Ydb_Query.TransactionSettings {
82167 return txSettings
83168}
84169
85- func (opts Settings ) ToYdbTableSettings () * Ydb_Table.TransactionSettings {
170+ func (opts Options ) ToYdbTableSettings () * Ydb_Table.TransactionSettings {
86171 txSettings := & Ydb_Table.TransactionSettings {}
87172 for _ , opt := range opts {
88173 if opt != nil {
@@ -94,7 +179,7 @@ func (opts Settings) ToYdbTableSettings() *Ydb_Table.TransactionSettings {
94179}
95180
96181// NewSettings returns transaction settings
97- func NewSettings (opts ... SettingsOption ) Settings {
182+ func NewSettings (opts ... SettingsOption ) Options {
98183 return opts
99184}
100185
0 commit comments