Skip to content

Commit 3aa7528

Browse files
committed
push code
1 parent 7797257 commit 3aa7528

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

batch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ func BuildToInsertBatchWithSchema(table string, models interface{}, driver strin
251251
return query, args, nil
252252
}
253253
}
254-
func BuildToSaveBatchWithSchema(table string, models interface{}, drive string, toArray func(interface{}) interface {
254+
func BuildToSaveBatch(table string, models interface{}, drive string, options ...*Schema) ([]Statement, error) {
255+
return BuildToSaveBatchWithArray(table, models, drive, nil, options...)
256+
}
257+
func BuildToSaveBatchWithArray(table string, models interface{}, drive string, toArray func(interface{}) interface {
255258
driver.Valuer
256259
sql.Scanner
257260
}, options ...*Schema) ([]Statement, error) {

client/instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (c *ProxyClient) SaveBatch(ctx context.Context, table string, models interf
167167
return 0, nil
168168
}
169169
} else {
170-
s, er1 := sql.BuildToSaveBatchWithSchema(table, models, driver, nil, options...)
170+
s, er1 := sql.BuildToSaveBatchWithArray(table, models, driver, nil, options...)
171171
if er1 != nil {
172172
return -1, er1
173173
}
@@ -243,7 +243,7 @@ func (c *ProxyClient) SaveBatchWithTx(ctx context.Context, tx string, commit boo
243243
return 0, nil
244244
}
245245
} else {
246-
s, er1 := sql.BuildToSaveBatchWithSchema(table, models, driver, nil, options...)
246+
s, er1 := sql.BuildToSaveBatchWithArray(table, models, driver, nil, options...)
247247
if er1 != nil {
248248
return -1, er1
249249
}

database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func SaveBatchWithArray(ctx context.Context, db *sql.DB, tableName string, model
512512
sql.Scanner
513513
}, options ...*Schema) (int64, error) {
514514
driver := GetDriver(db)
515-
stmts, er1 := BuildToSaveBatchWithSchema(tableName, models, driver, toArray, options...)
515+
stmts, er1 := BuildToSaveBatchWithArray(tableName, models, driver, toArray, options...)
516516
if er1 != nil {
517517
return 0, er1
518518
}

grpc-client/grpc_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (c *GRPCClient) SaveBatch(ctx context.Context, table string, models interfa
271271
return 0, nil
272272
}
273273
} else {
274-
s, er1 := sql.BuildToSaveBatchWithSchema(table, models, driver, nil, options...)
274+
s, er1 := sql.BuildToSaveBatchWithArray(table, models, driver, nil, options...)
275275
if er1 != nil {
276276
return -1, er1
277277
}
@@ -347,7 +347,7 @@ func (c *GRPCClient) SaveBatchWithTx(ctx context.Context, tx string, commit bool
347347
return 0, nil
348348
}
349349
} else {
350-
s, er1 := sql.BuildToSaveBatchWithSchema(table, models, driver, nil, options...)
350+
s, er1 := sql.BuildToSaveBatchWithArray(table, models, driver, nil, options...)
351351
if er1 != nil {
352352
return -1, er1
353353
}

one.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,13 @@ func JSONToColumns(model map[string]interface{}, m map[string]string) map[string
397397
}
398398

399399
func BuildToDelete(table string, ids map[string]interface{}, buildParam func(int) string) (string, []interface{}) {
400-
var values []interface{}
401-
var queryArr []string
400+
var args []interface{}
401+
var where []string
402402
i := 1
403-
for key, value := range ids {
404-
queryArr = append(queryArr, fmt.Sprintf("%v = %v", QuoteColumnName(key), buildParam(i)))
405-
values = append(values, value)
403+
for col, value := range ids {
404+
where = append(where, col+"="+buildParam(i))
405+
args = append(args, value)
406406
i++
407407
}
408-
q := strings.Join(queryArr, " and ")
409-
return fmt.Sprintf("delete from %v where %v", table, q), values
408+
return fmt.Sprintf("delete from %v where %v", table, strings.Join(where, " and ")), args
410409
}

0 commit comments

Comments
 (0)