@@ -2,18 +2,25 @@ package sqlbuilder
22
33import (
44 "database/sql"
5+ "sync"
56
67 "upper.io/db.v2/internal/sqladapter/exql"
78)
89
910type updater struct {
1011 * stringer
11- builder * sqlBuilder
12- table string
13- columnValues * exql.ColumnValues
14- limit int
15- where * exql.Where
16- arguments []interface {}
12+ builder * sqlBuilder
13+ table string
14+
15+ columnValues * exql.ColumnValues
16+ columnValuesArgs []interface {}
17+
18+ limit int
19+
20+ where * exql.Where
21+ whereArgs []interface {}
22+
23+ mu sync.Mutex
1724}
1825
1926func (qu * updater ) Set (terms ... interface {}) Updater {
@@ -36,28 +43,36 @@ func (qu *updater) Set(terms ...interface{}) Updater {
3643 cvs = append (cvs , cv )
3744 }
3845
39- args = append (args , qu .arguments ... )
40-
4146 qu .columnValues .Insert (cvs ... )
42- qu .arguments = append (qu .arguments , args ... )
47+ qu .columnValuesArgs = append (qu .columnValuesArgs , args ... )
4348 } else if len (terms ) > 1 {
4449 cv , arguments := qu .builder .t .ToColumnValues (terms )
4550 qu .columnValues .Insert (cv .ColumnValues ... )
46- qu .arguments = append (qu .arguments , arguments ... )
51+ qu .columnValuesArgs = append (qu .columnValuesArgs , arguments ... )
4752 }
4853
4954 return qu
5055}
5156
57+ func (qu * updater ) Arguments () []interface {} {
58+ qu .mu .Lock ()
59+ defer qu .mu .Unlock ()
60+
61+ return joinArguments (
62+ qu .columnValuesArgs ,
63+ qu .whereArgs ,
64+ )
65+ }
66+
5267func (qu * updater ) Where (terms ... interface {}) Updater {
5368 where , arguments := qu .builder .t .ToWhereWithArguments (terms )
5469 qu .where = & where
55- qu .arguments = append (qu .arguments , arguments ... )
70+ qu .whereArgs = append (qu .whereArgs , arguments ... )
5671 return qu
5772}
5873
5974func (qu * updater ) Exec () (sql.Result , error ) {
60- return qu .builder .sess .StatementExec (qu .statement (), qu .arguments ... )
75+ return qu .builder .sess .StatementExec (qu .statement (), qu .Arguments () ... )
6176}
6277
6378func (qu * updater ) Limit (limit int ) Updater {
0 commit comments