@@ -2,18 +2,25 @@ package sqlbuilder
2
2
3
3
import (
4
4
"database/sql"
5
+ "sync"
5
6
6
7
"upper.io/db.v2/internal/sqladapter/exql"
7
8
)
8
9
9
10
type updater struct {
10
11
* 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
17
24
}
18
25
19
26
func (qu * updater ) Set (terms ... interface {}) Updater {
@@ -36,28 +43,36 @@ func (qu *updater) Set(terms ...interface{}) Updater {
36
43
cvs = append (cvs , cv )
37
44
}
38
45
39
- args = append (args , qu .arguments ... )
40
-
41
46
qu .columnValues .Insert (cvs ... )
42
- qu .arguments = append (qu .arguments , args ... )
47
+ qu .columnValuesArgs = append (qu .columnValuesArgs , args ... )
43
48
} else if len (terms ) > 1 {
44
49
cv , arguments := qu .builder .t .ToColumnValues (terms )
45
50
qu .columnValues .Insert (cv .ColumnValues ... )
46
- qu .arguments = append (qu .arguments , arguments ... )
51
+ qu .columnValuesArgs = append (qu .columnValuesArgs , arguments ... )
47
52
}
48
53
49
54
return qu
50
55
}
51
56
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
+
52
67
func (qu * updater ) Where (terms ... interface {}) Updater {
53
68
where , arguments := qu .builder .t .ToWhereWithArguments (terms )
54
69
qu .where = & where
55
- qu .arguments = append (qu .arguments , arguments ... )
70
+ qu .whereArgs = append (qu .whereArgs , arguments ... )
56
71
return qu
57
72
}
58
73
59
74
func (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 () ... )
61
76
}
62
77
63
78
func (qu * updater ) Limit (limit int ) Updater {
0 commit comments