@@ -35,31 +35,91 @@ func TestBuilderCond(t *testing.T) {
35
35
"d IN (?,?)" ,
36
36
[]interface {}{"e" , "f" },
37
37
},
38
+ {
39
+ Eq {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
40
+ "e=(SELECT id FROM f WHERE g=?)" ,
41
+ []interface {}{1 },
42
+ },
43
+ {
44
+ Eq {"e" : Expr ("SELECT id FROM f WHERE g=?" , 1 )},
45
+ "e=(SELECT id FROM f WHERE g=?)" ,
46
+ []interface {}{1 },
47
+ },
38
48
{
39
49
Neq {"d" : []string {"e" , "f" }},
40
50
"d NOT IN (?,?)" ,
41
51
[]interface {}{"e" , "f" },
42
52
},
53
+ {
54
+ Neq {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
55
+ "e<>(SELECT id FROM f WHERE g=?)" ,
56
+ []interface {}{1 },
57
+ },
58
+ {
59
+ Neq {"e" : Expr ("SELECT id FROM f WHERE g=?" , 1 )},
60
+ "e<>(SELECT id FROM f WHERE g=?)" ,
61
+ []interface {}{1 },
62
+ },
43
63
{
44
64
Lt {"d" : 3 },
45
65
"d<?" ,
46
66
[]interface {}{3 },
47
67
},
68
+ {
69
+ Lt {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
70
+ "e<(SELECT id FROM f WHERE g=?)" ,
71
+ []interface {}{1 },
72
+ },
73
+ {
74
+ Lt {"e" : Expr ("SELECT id FROM f WHERE g=?" , 1 )},
75
+ "e<(SELECT id FROM f WHERE g=?)" ,
76
+ []interface {}{1 },
77
+ },
48
78
{
49
79
Lte {"d" : 3 },
50
80
"d<=?" ,
51
81
[]interface {}{3 },
52
82
},
83
+ {
84
+ Lte {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
85
+ "e<=(SELECT id FROM f WHERE g=?)" ,
86
+ []interface {}{1 },
87
+ },
88
+ {
89
+ Lte {"e" : Expr ("SELECT id FROM f WHERE g=?" , 1 )},
90
+ "e<=(SELECT id FROM f WHERE g=?)" ,
91
+ []interface {}{1 },
92
+ },
53
93
{
54
94
Gt {"d" : 3 },
55
95
"d>?" ,
56
96
[]interface {}{3 },
57
97
},
98
+ {
99
+ Gt {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
100
+ "e>(SELECT id FROM f WHERE g=?)" ,
101
+ []interface {}{1 },
102
+ },
103
+ {
104
+ Gt {"e" : Expr ("SELECT id FROM f WHERE g=?" , 1 )},
105
+ "e>(SELECT id FROM f WHERE g=?)" ,
106
+ []interface {}{1 },
107
+ },
58
108
{
59
109
Gte {"d" : 3 },
60
110
"d>=?" ,
61
111
[]interface {}{3 },
62
112
},
113
+ {
114
+ Gte {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
115
+ "e>=(SELECT id FROM f WHERE g=?)" ,
116
+ []interface {}{1 },
117
+ },
118
+ {
119
+ Gte {"e" : Expr ("SELECT id FROM f WHERE g=?" , 1 )},
120
+ "e>=(SELECT id FROM f WHERE g=?)" ,
121
+ []interface {}{1 },
122
+ },
63
123
{
64
124
Between {"d" , 0 , 2 },
65
125
"d BETWEEN ? AND ?" ,
@@ -100,6 +160,61 @@ func TestBuilderCond(t *testing.T) {
100
160
"0=1" ,
101
161
[]interface {}{},
102
162
},
163
+ {
164
+ In ("a" , []int8 {}),
165
+ "0=1" ,
166
+ []interface {}{},
167
+ },
168
+ {
169
+ In ("a" , []int16 {}),
170
+ "0=1" ,
171
+ []interface {}{},
172
+ },
173
+ {
174
+ In ("a" , []int32 {}),
175
+ "0=1" ,
176
+ []interface {}{},
177
+ },
178
+ {
179
+ In ("a" , []int64 {}),
180
+ "0=1" ,
181
+ []interface {}{},
182
+ },
183
+ {
184
+ In ("a" , []uint {}),
185
+ "0=1" ,
186
+ []interface {}{},
187
+ },
188
+ {
189
+ In ("a" , []uint8 {}),
190
+ "0=1" ,
191
+ []interface {}{},
192
+ },
193
+ {
194
+ In ("a" , []uint16 {}),
195
+ "0=1" ,
196
+ []interface {}{},
197
+ },
198
+ {
199
+ In ("a" , []uint32 {}),
200
+ "0=1" ,
201
+ []interface {}{},
202
+ },
203
+ {
204
+ In ("a" , []uint64 {}),
205
+ "0=1" ,
206
+ []interface {}{},
207
+ },
208
+ {
209
+ In ("a" , []interface {}{1 , 2 , 3 }).And (Eq {"b" : "c" }),
210
+ "a IN (?,?,?) AND b=?" ,
211
+ []interface {}{1 , 2 , 3 , "c" },
212
+ },
213
+ {
214
+ In ("a" , Select ("id" ).From ("b" ).Where (Eq {"c" : 1 })),
215
+ "a IN (SELECT id FROM b WHERE c=?)" ,
216
+ []interface {}{1 },
217
+ },
103
218
{
104
219
NotIn ("a" , Expr ("select id from x where name > ?" , "b" )),
105
220
"a NOT IN (select id from x where name > ?)" ,
@@ -110,11 +225,71 @@ func TestBuilderCond(t *testing.T) {
110
225
"0=0" ,
111
226
[]interface {}{},
112
227
},
228
+ {
229
+ NotIn ("a" , []int8 {}),
230
+ "0=0" ,
231
+ []interface {}{},
232
+ },
233
+ {
234
+ NotIn ("a" , []int16 {}),
235
+ "0=0" ,
236
+ []interface {}{},
237
+ },
238
+ {
239
+ NotIn ("a" , []int32 {}),
240
+ "0=0" ,
241
+ []interface {}{},
242
+ },
243
+ {
244
+ NotIn ("a" , []int64 {}),
245
+ "0=0" ,
246
+ []interface {}{},
247
+ },
248
+ {
249
+ NotIn ("a" , []uint {}),
250
+ "0=0" ,
251
+ []interface {}{},
252
+ },
253
+ {
254
+ NotIn ("a" , []uint8 {}),
255
+ "0=0" ,
256
+ []interface {}{},
257
+ },
258
+ {
259
+ NotIn ("a" , []uint16 {}),
260
+ "0=0" ,
261
+ []interface {}{},
262
+ },
263
+ {
264
+ NotIn ("a" , []uint32 {}),
265
+ "0=0" ,
266
+ []interface {}{},
267
+ },
268
+ {
269
+ NotIn ("a" , []uint64 {}),
270
+ "0=0" ,
271
+ []interface {}{},
272
+ },
273
+ {
274
+ NotIn ("a" , []interface {}{1 , 2 , 3 }).And (Eq {"b" : "c" }),
275
+ "a NOT IN (?,?,?) AND b=?" ,
276
+ []interface {}{1 , 2 , 3 , "c" },
277
+ },
278
+ {
279
+ NotIn ("a" , Select ("id" ).From ("b" ).Where (Eq {"c" : 1 })),
280
+ "a NOT IN (SELECT id FROM b WHERE c=?)" ,
281
+ []interface {}{1 },
282
+ },
113
283
{
114
284
Or (Eq {"a" : 1 , "b" : 2 }, Eq {"c" : 3 , "d" : 4 }),
115
285
"(a=? AND b=?) OR (c=? AND d=?)" ,
116
286
[]interface {}{1 , 2 , 3 , 4 },
117
287
},
288
+ {
289
+ Not {Eq {"a" : 1 , "b" : 2 }},
290
+ "NOT (a=? AND b=?)" ,
291
+ []interface {}{1 , 2 },
292
+ },
118
293
}
119
294
120
295
for _ , k := range cases {
0 commit comments