@@ -39,23 +39,19 @@ type Result struct {
39
39
columns []interface {}
40
40
orderBy []interface {}
41
41
groupBy []interface {}
42
- conds []interface {}
42
+ conds [][] interface {}
43
43
err error
44
44
errMu sync.RWMutex
45
45
iterMu sync.Mutex
46
46
}
47
47
48
- func filter (conds []interface {}) []interface {} {
49
- return conds
50
- }
51
-
52
48
// NewResult creates and Results a new Result set on the given table, this set
53
49
// is limited by the given exql.Where conditions.
54
50
func NewResult (b sqlbuilder.Builder , table string , conds []interface {}) * Result {
55
51
return & Result {
56
52
b : b ,
57
53
table : table ,
58
- conds : conds ,
54
+ conds : [][] interface {}{ conds } ,
59
55
}
60
56
}
61
57
@@ -81,13 +77,13 @@ func (r *Result) Err() error {
81
77
82
78
// Where sets conditions for the result set.
83
79
func (r * Result ) Where (conds ... interface {}) db.Result {
84
- r .conds = conds
80
+ r .conds = append ( r . conds , conds )
85
81
return r
86
82
}
87
83
88
84
// And adds more conditions on top of the existing ones.
89
85
func (r * Result ) And (conds ... interface {}) db.Result {
90
- r .conds = append (r .conds , conds ... )
86
+ r .conds = append (r .conds , conds )
91
87
return r
92
88
}
93
89
@@ -162,9 +158,12 @@ func (r *Result) Next(dst interface{}) bool {
162
158
// Delete deletes all matching items from the collection.
163
159
func (r * Result ) Delete () error {
164
160
q := r .b .DeleteFrom (r .table ).
165
- Where (filter (r .conds )... ).
166
161
Limit (r .limit )
167
162
163
+ for i := range r .conds {
164
+ q = q .And (r .conds [i ]... )
165
+ }
166
+
168
167
_ , err := q .Exec ()
169
168
return r .setErr (err )
170
169
}
@@ -182,9 +181,12 @@ func (r *Result) Close() error {
182
181
func (r * Result ) Update (values interface {}) error {
183
182
q := r .b .Update (r .table ).
184
183
Set (values ).
185
- Where (filter (r .conds )... ).
186
184
Limit (r .limit )
187
185
186
+ for i := range r .conds {
187
+ q = q .And (r .conds [i ]... )
188
+ }
189
+
188
190
_ , err := q .Exec ()
189
191
return r .setErr (err )
190
192
}
@@ -197,10 +199,13 @@ func (r *Result) Count() (uint64, error) {
197
199
198
200
q := r .b .Select (db .Raw ("count(1) AS _t" )).
199
201
From (r .table ).
200
- Where (filter (r .conds )... ).
201
202
GroupBy (r .groupBy ... ).
202
203
Limit (1 )
203
204
205
+ for i := range r .conds {
206
+ q = q .And (r .conds [i ]... )
207
+ }
208
+
204
209
if err := q .Iterator ().One (& counter ); err != nil {
205
210
if err == db .ErrNoMoreRows {
206
211
return 0 , nil
@@ -215,10 +220,13 @@ func (r *Result) buildSelect() sqlbuilder.Selector {
215
220
q := r .b .Select (r .fields ... )
216
221
217
222
q .From (r .table )
218
- q .Where (filter (r .conds )... )
219
223
q .Limit (r .limit )
220
224
q .Offset (r .offset )
221
225
226
+ for i := range r .conds {
227
+ q = q .And (r .conds [i ]... )
228
+ }
229
+
222
230
q .GroupBy (r .groupBy ... )
223
231
q .OrderBy (r .orderBy ... )
224
232
0 commit comments