@@ -102,63 +102,61 @@ func (c *ProxyClient) QueryWithTx(ctx context.Context, tx string, commit bool, r
102
102
return err
103
103
}
104
104
105
- func (c * ProxyClient ) Insert (ctx context.Context , table string , model interface {}, driver string , options ... func ( int ) string ) (int64 , error ) {
106
- var buildParam func ( int ) string
105
+ func (c * ProxyClient ) Insert (ctx context.Context , table string , model interface {}, buildParam func ( int ) string , options ... bool ) (int64 , error ) {
106
+ boolSupport := false
107
107
if len (options ) > 0 {
108
- buildParam = options [0 ]
109
- } else {
110
- buildParam = sql .GetBuildByDriver (driver )
108
+ boolSupport = options [0 ]
111
109
}
112
- boolSupport := driver == sql .DriverPostgres || driver == sql .DriverCassandra
113
110
s , values := sql .BuildToInsert (table , model , buildParam , nil , boolSupport )
114
111
return c .Exec (ctx , s , values ... )
115
112
}
116
- func (c * ProxyClient ) Update (ctx context.Context , table string , model interface {}, driver string , options ... func ( int ) string ) (int64 , error ) {
117
- var buildParam func ( int ) string
113
+ func (c * ProxyClient ) Update (ctx context.Context , table string , model interface {}, buildParam func ( int ) string , options ... bool ) (int64 , error ) {
114
+ boolSupport := false
118
115
if len (options ) > 0 {
119
- buildParam = options [0 ]
120
- } else {
121
- buildParam = sql .GetBuildByDriver (driver )
116
+ boolSupport = options [0 ]
122
117
}
123
- boolSupport := driver == sql .DriverPostgres || driver == sql .DriverCassandra
124
118
s , values := sql .BuildToUpdate (table , model , buildParam , nil , boolSupport )
125
119
return c .Exec (ctx , s , values ... )
126
120
}
127
- func (c * ProxyClient ) Save (ctx context.Context , table string , model interface {}, options ... string ) (int64 , error ) {
128
- driver := sql .DriverPostgres
129
- var buildParam func (int ) string
130
- if len (options ) > 0 {
131
- driver = options [0 ]
132
- }
133
- buildParam = sql .GetBuildByDriver (driver )
134
- s , values , err := sql .BuildToSave (table , model , driver , buildParam )
135
- if err != nil {
136
- return - 1 , err
121
+ func (c * ProxyClient ) Save (ctx context.Context , table string , model interface {}, driver string , options ... sql.Schema ) (int64 , error ) {
122
+ buildParam := sql .GetBuildByDriver (driver )
123
+ if driver == sql .DriverPostgres || driver == sql .DriverOracle || driver == sql .DriverMysql || driver == sql .DriverMssql || driver == sql .DriverSqlite3 {
124
+ s , values , err := sql .BuildToSaveWithSchema (table , model , driver , buildParam , nil , options ... )
125
+ if err != nil {
126
+ return - 1 , err
127
+ }
128
+ return c .Exec (ctx , s , values ... )
129
+ } else {
130
+ s , values := sql .BuildToInsertWithSchema (table , model , - 1 , buildParam , true , true , nil , options ... )
131
+ return c .Exec (ctx , s , values ... )
137
132
}
138
- return c .Exec (ctx , s , values ... )
139
133
}
140
- func (c * ProxyClient ) InsertBatch (ctx context.Context , table string , models interface {}, driver string , options ... func (int ) string ) (int64 , error ) {
141
- var buildParam func (int ) string
142
- if len (options ) > 0 {
143
- buildParam = options [0 ]
134
+ func (c * ProxyClient ) InsertBatch (ctx context.Context , table string , models interface {}, driver string ) (int64 , error ) {
135
+ buildParam := sql .GetBuildByDriver (driver )
136
+ if driver == sql .DriverPostgres || driver == sql .DriverOracle || driver == sql .DriverMysql || driver == sql .DriverMssql || driver == sql .DriverSqlite3 {
137
+ s , values , err := sql .BuildToInsertBatch (table , models , driver , nil , buildParam )
138
+ if err != nil {
139
+ return - 1 , err
140
+ }
141
+ return c .Exec (ctx , s , values ... )
144
142
} else {
145
- buildParam = sql .GetBuildByDriver (driver )
146
- }
147
- // boolSupport := driver == sql.DriverPostgres || driver == sql.DriverCassandra
148
- s , values , err := sql .BuildToInsertBatch (table , models , driver , nil , buildParam )
149
- if err != nil {
150
- return - 1 , err
143
+ boolSupport := driver == sql .DriverCassandra
144
+ s , er0 := sql .BuildInsertStatements (table , models , buildParam , nil , boolSupport )
145
+ if er0 != nil {
146
+ return - 1 , er0
147
+ }
148
+ if len (s ) > 0 {
149
+ return c .ExecBatch (ctx , false , s ... )
150
+ } else {
151
+ return 0 , nil
152
+ }
151
153
}
152
- return c .Exec (ctx , s , values ... )
153
154
}
154
- func (c * ProxyClient ) UpdateBatch (ctx context.Context , table string , models interface {}, driver string , options ... func ( int ) string ) (int64 , error ) {
155
- var buildParam func ( int ) string
155
+ func (c * ProxyClient ) UpdateBatch (ctx context.Context , table string , models interface {}, buildParam func ( int ) string , options ... bool ) (int64 , error ) {
156
+ boolSupport := false
156
157
if len (options ) > 0 {
157
- buildParam = options [0 ]
158
- } else {
159
- buildParam = sql .GetBuildByDriver (driver )
158
+ boolSupport = options [0 ]
160
159
}
161
- boolSupport := driver == sql .DriverPostgres || driver == sql .DriverCassandra
162
160
s , err := sql .BuildToUpdateBatch (table , models , buildParam , nil , boolSupport )
163
161
if err != nil {
164
162
return - 1 , err
@@ -169,80 +167,97 @@ func (c *ProxyClient) UpdateBatch(ctx context.Context, table string, models inte
169
167
return 0 , nil
170
168
}
171
169
}
172
- func (c * ProxyClient ) SaveBatch (ctx context.Context , table string , models interface {}, options ... string ) (int64 , error ) {
173
- driver := sql .DriverPostgres
174
- var buildParam func (int ) string
175
- if len (options ) > 0 {
176
- driver = options [0 ]
177
- }
178
- buildParam = sql .GetBuildByDriver (driver )
179
- s , err := sql .BuildToSaveBatch (table , models , driver , buildParam )
180
- if err != nil {
181
- return - 1 , err
182
- }
183
- if len (s ) > 0 {
184
- return c .ExecBatch (ctx , false , s ... )
170
+ func (c * ProxyClient ) SaveBatch (ctx context.Context , table string , models interface {}, driver string ) (int64 , error ) {
171
+ if driver == sql .DriverCassandra {
172
+ s , er0 := sql .BuildInsertStatementsWithVersion (table , models , - 1 , sql .BuildParam , nil , true , true )
173
+ if er0 != nil {
174
+ return - 1 , er0
175
+ }
176
+ if len (s ) > 0 {
177
+ return c .ExecBatch (ctx , false , s ... )
178
+ } else {
179
+ return 0 , nil
180
+ }
185
181
} else {
186
- return 0 , nil
182
+ s , er1 := sql .BuildToSaveBatch (table , models , driver , nil )
183
+ if er1 != nil {
184
+ return - 1 , er1
185
+ }
186
+ if len (s ) > 0 {
187
+ return c .ExecBatch (ctx , false , s ... )
188
+ } else {
189
+ return 0 , nil
190
+ }
187
191
}
188
192
}
189
- func (c * ProxyClient ) InsertWithTx (ctx context.Context , tx string , commit bool , table string , model interface {}, driver string , options ... func ( int ) string ) (int64 , error ) {
190
- var buildParam func ( int ) string
193
+ func (c * ProxyClient ) InsertWithTx (ctx context.Context , tx string , table string , model interface {}, buildParam func ( int ) string , options ... bool ) (int64 , error ) {
194
+ boolSupport := false
191
195
if len (options ) > 0 {
192
- buildParam = options [0 ]
193
- } else {
194
- buildParam = sql .GetBuildByDriver (driver )
196
+ boolSupport = options [0 ]
195
197
}
196
- boolSupport := driver == sql . DriverPostgres || driver == sql . DriverCassandra
198
+ commit := true
197
199
s , values := sql .BuildToInsert (table , model , buildParam , nil , boolSupport )
198
200
return c .ExecWithTx (ctx , tx , commit , s , values ... )
199
201
}
200
- func (c * ProxyClient ) UpdateWithTx (ctx context.Context , tx string , commit bool , table string , model interface {}, driver string , options ... func ( int ) string ) (int64 , error ) {
201
- var buildParam func ( int ) string
202
+ func (c * ProxyClient ) UpdateWithTx (ctx context.Context , tx string , table string , model interface {}, buildParam func ( int ) string , options ... bool ) (int64 , error ) {
203
+ boolSupport := false
202
204
if len (options ) > 0 {
203
- buildParam = options [0 ]
204
- } else {
205
- buildParam = sql .GetBuildByDriver (driver )
205
+ boolSupport = options [0 ]
206
206
}
207
- boolSupport := driver == sql . DriverPostgres || driver == sql . DriverCassandra
207
+ commit := true
208
208
s , values := sql .BuildToUpdate (table , model , buildParam , nil , boolSupport )
209
209
return c .ExecWithTx (ctx , tx , commit , s , values ... )
210
210
}
211
- func (c * ProxyClient ) SaveWithTx (ctx context.Context , tx string , commit bool , table string , model interface {}, options ... string ) (int64 , error ) {
212
- driver := sql .DriverPostgres
213
- var buildParam func ( int ) string
211
+ func (c * ProxyClient ) SaveWithTx (ctx context.Context , tx string , table string , model interface {}, driver string , options ... bool ) (int64 , error ) {
212
+ buildParam := sql .GetBuildByDriver ( driver )
213
+ commit := false
214
214
if len (options ) > 0 {
215
- driver = options [0 ]
215
+ commit = options [0 ]
216
216
}
217
- buildParam = sql .GetBuildByDriver (driver )
218
- s , values , err := sql .BuildToSave (table , model , driver , buildParam )
219
- if err != nil {
220
- return - 1 , err
217
+ if driver == sql .DriverCassandra {
218
+ s , values := sql .BuildToInsertWithSchema (table , model , - 1 , buildParam , true , true , nil )
219
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
220
+ } else {
221
+ s , values , err := sql .BuildToSaveWithSchema (table , model , driver , buildParam , nil )
222
+ if err != nil {
223
+ return - 1 , err
224
+ }
225
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
221
226
}
222
- return c .ExecWithTx (ctx , tx , commit , s , values ... )
223
227
}
224
- func (c * ProxyClient ) InsertBatchWithTx (ctx context.Context , tx string , commit bool , table string , models interface {}, driver string , options ... func (int ) string ) (int64 , error ) {
225
- var buildParam func (int ) string
228
+ func (c * ProxyClient ) InsertBatchWithTx (ctx context.Context , tx string , table string , models interface {}, driver string , options ... bool ) (int64 , error ) {
229
+ buildParam := sql .GetBuildByDriver (driver )
230
+ commit := false
226
231
if len (options ) > 0 {
227
- buildParam = options [0 ]
232
+ commit = options [0 ]
233
+ }
234
+ if driver == sql .DriverCassandra {
235
+ s , er0 := sql .BuildInsertStatements (table , models , buildParam , nil , true )
236
+ if er0 != nil {
237
+ return - 1 , er0
238
+ }
239
+ if len (s ) > 0 {
240
+ return c .ExecBatchWithTx (ctx , tx , commit , false , s ... )
241
+ } else {
242
+ return 0 , nil
243
+ }
228
244
} else {
229
- buildParam = sql .GetBuildByDriver (driver )
245
+ s , values , err := sql .BuildToInsertBatch (table , models , driver , nil , buildParam )
246
+ if err != nil {
247
+ return - 1 , err
248
+ }
249
+ return c .ExecWithTx (ctx , tx , commit , s , values ... )
230
250
}
231
- // boolSupport := driver == sql.DriverPostgres || driver == sql.DriverCassandra
232
- s , values , err := sql .BuildToInsertBatch (table , models , driver , nil , buildParam )
233
- if err != nil {
234
- return - 1 , err
235
- }
236
- return c .ExecWithTx (ctx , tx , commit , s , values ... )
237
251
}
238
- func (c * ProxyClient ) UpdateBatchWithTx (ctx context.Context , tx string , commit bool , table string , models interface {}, driver string , options ... func ( int ) string ) (int64 , error ) {
239
- var buildParam func ( int ) string
252
+ func (c * ProxyClient ) UpdateBatchWithTx (ctx context.Context , tx string , table string , models interface {}, buildParam func ( int ) string , options ... bool ) (int64 , error ) {
253
+ boolSupport := false
240
254
if len (options ) > 0 {
241
- buildParam = options [0 ]
242
- } else {
243
- buildParam = sql .GetBuildByDriver (driver )
255
+ boolSupport = options [0 ]
256
+ }
257
+ commit := false
258
+ if len (options ) > 1 {
259
+ commit = options [1 ]
244
260
}
245
- boolSupport := driver == sql .DriverPostgres || driver == sql .DriverCassandra
246
261
s , err := sql .BuildToUpdateBatch (table , models , buildParam , nil , boolSupport )
247
262
if err != nil {
248
263
return - 1 , err
@@ -253,20 +268,61 @@ func (c *ProxyClient) UpdateBatchWithTx(ctx context.Context, tx string, commit b
253
268
return 0 , nil
254
269
}
255
270
}
256
- func (c * ProxyClient ) SaveBatchWithTx (ctx context.Context , tx string , commit bool , table string , models interface {}, options ... string ) (int64 , error ) {
257
- driver := sql .DriverPostgres
258
- var buildParam func (int ) string
271
+ func (c * ProxyClient ) SaveBatchWithTx (ctx context.Context , tx string , table string , models interface {}, driver string , options ... bool ) (int64 , error ) {
272
+ commit := false
259
273
if len (options ) > 0 {
260
- driver = options [0 ]
274
+ commit = options [0 ]
275
+ }
276
+ if driver == sql .DriverCassandra {
277
+ s , er0 := sql .BuildInsertStatementsWithVersion (table , models , - 1 , sql .BuildParam , nil , true , true )
278
+ if er0 != nil {
279
+ return - 1 , er0
280
+ }
281
+ if len (s ) > 0 {
282
+ return c .ExecBatchWithTx (ctx , tx , commit , false , s ... )
283
+ } else {
284
+ return 0 , nil
285
+ }
286
+ } else {
287
+ s , er1 := sql .BuildToSaveBatch (table , models , driver , nil )
288
+ if er1 != nil {
289
+ return - 1 , er1
290
+ }
291
+ if len (s ) > 0 {
292
+ return c .ExecBatchWithTx (ctx , tx , commit , false , s ... )
293
+ } else {
294
+ return 0 , nil
295
+ }
261
296
}
262
- buildParam = sql .GetBuildByDriver (driver )
263
- s , err := sql .BuildToSaveBatch (table , models , driver , buildParam )
264
- if err != nil {
265
- return - 1 , err
297
+ }
298
+
299
+ func (c * ProxyClient ) InsertAndCommit (ctx context.Context , tx string , table string , model interface {}, buildParam func (int ) string , options ... bool ) (int64 , error ) {
300
+ boolSupport := false
301
+ if len (options ) > 0 {
302
+ boolSupport = options [0 ]
266
303
}
267
- if len (s ) > 0 {
268
- return c .ExecBatchWithTx (ctx , tx , commit , false , s ... )
269
- } else {
270
- return 0 , nil
304
+ return c .InsertWithTx (ctx , tx , table , model , buildParam , boolSupport , true )
305
+ }
306
+ func (c * ProxyClient ) UpdateAndCommit (ctx context.Context , tx string , table string , model interface {}, driver string , buildParam func (int ) string , options ... bool ) (int64 , error ) {
307
+ boolSupport := false
308
+ if len (options ) > 0 {
309
+ boolSupport = options [0 ]
271
310
}
311
+ return c .UpdateWithTx (ctx , tx , table , model , buildParam , boolSupport , true )
312
+ }
313
+ func (c * ProxyClient ) SaveAndCommit (ctx context.Context , tx string , table string , model interface {}, driver string ) (int64 , error ) {
314
+ return c .SaveWithTx (ctx , tx , table , model , driver , true )
315
+ }
316
+ func (c * ProxyClient ) InsertBatchAndCommit (ctx context.Context , tx string , table string , models interface {}, driver string ) (int64 , error ) {
317
+ return c .InsertBatchWithTx (ctx , tx , table , models , driver , true )
318
+ }
319
+ func (c * ProxyClient ) UpdateBatchAndCommit (ctx context.Context , tx string , table string , models interface {}, buildParam func (int ) string , options ... bool ) (int64 , error ) {
320
+ boolSupport := false
321
+ if len (options ) > 0 {
322
+ boolSupport = options [0 ]
323
+ }
324
+ return c .UpdateBatchWithTx (ctx , tx , table , models , buildParam , boolSupport , true )
325
+ }
326
+ func (c * ProxyClient ) SaveBatchAndCommit (ctx context.Context , tx string , table string , models interface {}, driver string ) (int64 , error ) {
327
+ return c .SaveBatchWithTx (ctx , tx , table , models , driver , true )
272
328
}
0 commit comments