9
9
querySerializableReadWrite = & Ydb_Query.TransactionSettings_SerializableReadWrite {
10
10
SerializableReadWrite : & Ydb_Query.SerializableModeSettings {},
11
11
}
12
+ querySerializableReadWriteTxSelector = & Ydb_Query.TransactionControl_BeginTx {
13
+ BeginTx : & Ydb_Query.TransactionSettings {
14
+ TxMode : querySerializableReadWrite ,
15
+ },
16
+ }
12
17
queryStaleReadOnly = & Ydb_Query.TransactionSettings_StaleReadOnly {
13
18
StaleReadOnly : & Ydb_Query.StaleModeSettings {},
14
19
}
20
+ queryStaleReadOnlyTxSelector = & Ydb_Query.TransactionControl_BeginTx {
21
+ BeginTx : & Ydb_Query.TransactionSettings {
22
+ TxMode : queryStaleReadOnly ,
23
+ },
24
+ }
15
25
querySnapshotReadOnly = & Ydb_Query.TransactionSettings_SnapshotReadOnly {
16
26
SnapshotReadOnly : & Ydb_Query.SnapshotModeSettings {},
17
27
}
28
+ querySnapshotReadOnlyTxSelector = & Ydb_Query.TransactionControl_BeginTx {
29
+ BeginTx : & Ydb_Query.TransactionSettings {
30
+ TxMode : querySnapshotReadOnly ,
31
+ },
32
+ }
18
33
queryOnlineReadOnlyAllowInconsistentReads = & Ydb_Query.TransactionSettings_OnlineReadOnly {
19
34
OnlineReadOnly : & Ydb_Query.OnlineModeSettings {AllowInconsistentReads : true },
20
35
}
36
+ queryOnlineReadOnlyAllowInconsistentReadsTxSelector = & Ydb_Query.TransactionControl_BeginTx {
37
+ BeginTx : & Ydb_Query.TransactionSettings {
38
+ TxMode : queryOnlineReadOnlyAllowInconsistentReads ,
39
+ },
40
+ }
21
41
queryOnlineReadOnlyForbidInconsistentReads = & Ydb_Query.TransactionSettings_OnlineReadOnly {
22
42
OnlineReadOnly : & Ydb_Query.OnlineModeSettings {AllowInconsistentReads : false },
23
43
}
44
+ queryOnlineReadOnlyForbidInconsistentReadsTxSelector = & Ydb_Query.TransactionControl_BeginTx {
45
+ BeginTx : & Ydb_Query.TransactionSettings {
46
+ TxMode : queryOnlineReadOnlyForbidInconsistentReads ,
47
+ },
48
+ }
24
49
tableSerializableReadWrite = & Ydb_Table.TransactionSettings_SerializableReadWrite {
25
50
SerializableReadWrite : & Ydb_Table.SerializableModeSettings {},
26
51
}
52
+ tableSerializableReadWriteTxSelector = & Ydb_Table.TransactionControl_BeginTx {
53
+ BeginTx : & Ydb_Table.TransactionSettings {
54
+ TxMode : tableSerializableReadWrite ,
55
+ },
56
+ }
27
57
tableStaleReadOnly = & Ydb_Table.TransactionSettings_StaleReadOnly {
28
58
StaleReadOnly : & Ydb_Table.StaleModeSettings {},
29
59
}
60
+ tableStaleReadOnlyTxSelector = & Ydb_Table.TransactionControl_BeginTx {
61
+ BeginTx : & Ydb_Table.TransactionSettings {
62
+ TxMode : tableStaleReadOnly ,
63
+ },
64
+ }
30
65
tableSnapshotReadOnly = & Ydb_Table.TransactionSettings_SnapshotReadOnly {
31
66
SnapshotReadOnly : & Ydb_Table.SnapshotModeSettings {},
32
67
}
68
+ tableSnapshotReadOnlyTxSelector = & Ydb_Table.TransactionControl_BeginTx {
69
+ BeginTx : & Ydb_Table.TransactionSettings {
70
+ TxMode : tableSnapshotReadOnly ,
71
+ },
72
+ }
33
73
tableOnlineReadOnlyAllowInconsistentReads = & Ydb_Table.TransactionSettings_OnlineReadOnly {
34
74
OnlineReadOnly : & Ydb_Table.OnlineModeSettings {AllowInconsistentReads : true },
35
75
}
76
+ tableOnlineReadOnlyAllowInconsistentReadsTxSelector = & Ydb_Table.TransactionControl_BeginTx {
77
+ BeginTx : & Ydb_Table.TransactionSettings {
78
+ TxMode : tableOnlineReadOnlyAllowInconsistentReads ,
79
+ },
80
+ }
36
81
tableOnlineReadOnlyForbidInconsistentReads = & Ydb_Table.TransactionSettings_OnlineReadOnly {
37
82
OnlineReadOnly : & Ydb_Table.OnlineModeSettings {AllowInconsistentReads : false },
38
83
}
84
+ tableOnlineReadOnlyForbidInconsistentReadsTxSelector = & Ydb_Table.TransactionControl_BeginTx {
85
+ BeginTx : & Ydb_Table.TransactionSettings {
86
+ TxMode : tableOnlineReadOnlyForbidInconsistentReads ,
87
+ },
88
+ }
39
89
)
40
90
41
91
// Transaction settings options
@@ -44,10 +94,45 @@ type (
44
94
ApplyQueryTxSettingsOption (txSettings * Ydb_Query.TransactionSettings )
45
95
ApplyTableTxSettingsOption (txSettings * Ydb_Table.TransactionSettings )
46
96
}
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
48
105
)
49
106
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 ) {
51
136
beginTx := & Ydb_Table.TransactionControl_BeginTx {
52
137
BeginTx : & Ydb_Table.TransactionSettings {},
53
138
}
@@ -59,7 +144,7 @@ func (opts Settings) applyTableTxSelector(txControl *Ydb_Table.TransactionContro
59
144
txControl .TxSelector = beginTx
60
145
}
61
146
62
- func (opts Settings ) applyQueryTxSelector (txControl * Ydb_Query.TransactionControl ) {
147
+ func (opts Options ) applyQueryTxSelector (txControl * Ydb_Query.TransactionControl ) {
63
148
beginTx := & Ydb_Query.TransactionControl_BeginTx {
64
149
BeginTx : & Ydb_Query.TransactionSettings {},
65
150
}
@@ -71,7 +156,7 @@ func (opts Settings) applyQueryTxSelector(txControl *Ydb_Query.TransactionContro
71
156
txControl .TxSelector = beginTx
72
157
}
73
158
74
- func (opts Settings ) ToYdbQuerySettings () * Ydb_Query.TransactionSettings {
159
+ func (opts Options ) ToYdbQuerySettings () * Ydb_Query.TransactionSettings {
75
160
txSettings := & Ydb_Query.TransactionSettings {}
76
161
for _ , opt := range opts {
77
162
if opt != nil {
@@ -82,7 +167,7 @@ func (opts Settings) ToYdbQuerySettings() *Ydb_Query.TransactionSettings {
82
167
return txSettings
83
168
}
84
169
85
- func (opts Settings ) ToYdbTableSettings () * Ydb_Table.TransactionSettings {
170
+ func (opts Options ) ToYdbTableSettings () * Ydb_Table.TransactionSettings {
86
171
txSettings := & Ydb_Table.TransactionSettings {}
87
172
for _ , opt := range opts {
88
173
if opt != nil {
@@ -94,7 +179,7 @@ func (opts Settings) ToYdbTableSettings() *Ydb_Table.TransactionSettings {
94
179
}
95
180
96
181
// NewSettings returns transaction settings
97
- func NewSettings (opts ... SettingsOption ) Settings {
182
+ func NewSettings (opts ... SettingsOption ) Options {
98
183
return opts
99
184
}
100
185
0 commit comments