@@ -43,6 +43,16 @@ func TestBuilderCond(t *testing.T) {
4343"e=(SELECT id FROM f WHERE g=?)" ,
4444[]interface {}{1 },
4545},
46+ {
47+ Like {"a" , "%1" }.And (Like {"b" , "%2" }),
48+ "a LIKE ? AND b LIKE ?" ,
49+ []interface {}{"%1" , "%2" },
50+ },
51+ {
52+ Like {"a" , "%1" }.Or (Like {"b" , "%2" }),
53+ "a LIKE ? OR b LIKE ?" ,
54+ []interface {}{"%1" , "%2" },
55+ },
4656{
4757Neq {"d" : []string {"e" , "f" }},
4858"d NOT IN (?,?)" ,
@@ -63,6 +73,16 @@ func TestBuilderCond(t *testing.T) {
6373"d<?" ,
6474[]interface {}{3 },
6575},
76+ {
77+ Lt {"d" : 3 }.And (Lt {"e" : 4 }),
78+ "d<? AND e<?" ,
79+ []interface {}{3 , 4 },
80+ },
81+ {
82+ Lt {"d" : 3 }.Or (Lt {"e" : 4 }),
83+ "d<? OR e<?" ,
84+ []interface {}{3 , 4 },
85+ },
6686{
6787Lt {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
6888"e<(SELECT id FROM f WHERE g=?)" ,
@@ -78,6 +98,16 @@ func TestBuilderCond(t *testing.T) {
7898"d<=?" ,
7999[]interface {}{3 },
80100},
101+ {
102+ Lte {"d" : 3 }.And (Lte {"e" : 4 }),
103+ "d<=? AND e<=?" ,
104+ []interface {}{3 , 4 },
105+ },
106+ {
107+ Lte {"d" : 3 }.Or (Lte {"e" : 4 }),
108+ "d<=? OR e<=?" ,
109+ []interface {}{3 , 4 },
110+ },
81111{
82112Lte {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
83113"e<=(SELECT id FROM f WHERE g=?)" ,
@@ -93,6 +123,16 @@ func TestBuilderCond(t *testing.T) {
93123"d>?" ,
94124[]interface {}{3 },
95125},
126+ {
127+ Gt {"d" : 3 }.And (Gt {"e" : 4 }),
128+ "d>? AND e>?" ,
129+ []interface {}{3 , 4 },
130+ },
131+ {
132+ Gt {"d" : 3 }.Or (Gt {"e" : 4 }),
133+ "d>? OR e>?" ,
134+ []interface {}{3 , 4 },
135+ },
96136{
97137Gt {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
98138"e>(SELECT id FROM f WHERE g=?)" ,
@@ -108,6 +148,16 @@ func TestBuilderCond(t *testing.T) {
108148"d>=?" ,
109149[]interface {}{3 },
110150},
151+ {
152+ Gte {"d" : 3 }.And (Gte {"e" : 4 }),
153+ "d>=? AND e>=?" ,
154+ []interface {}{3 , 4 },
155+ },
156+ {
157+ Gte {"d" : 3 }.Or (Gte {"e" : 4 }),
158+ "d>=? OR e>=?" ,
159+ []interface {}{3 , 4 },
160+ },
111161{
112162Gte {"e" : Select ("id" ).From ("f" ).Where (Eq {"g" : 1 })},
113163"e>=(SELECT id FROM f WHERE g=?)" ,
@@ -123,11 +173,61 @@ func TestBuilderCond(t *testing.T) {
123173"d BETWEEN ? AND ?" ,
124174[]interface {}{0 , 2 },
125175},
176+ {
177+ Between {"d" , 0 , Expr ("CAST('2003-01-01' AS DATE)" )},
178+ "d BETWEEN ? AND CAST('2003-01-01' AS DATE)" ,
179+ []interface {}{0 },
180+ },
181+ {
182+ Between {"d" , Expr ("CAST('2003-01-01' AS DATE)" ), 2 },
183+ "d BETWEEN CAST('2003-01-01' AS DATE) AND ?" ,
184+ []interface {}{2 },
185+ },
186+ {
187+ Between {"d" , Expr ("CAST('2003-01-01' AS DATE)" ), Expr ("CAST('2003-01-01' AS DATE)" )},
188+ "d BETWEEN CAST('2003-01-01' AS DATE) AND CAST('2003-01-01' AS DATE)" ,
189+ []interface {}{},
190+ },
191+ {
192+ Between {"d" , 0 , 2 }.And (Between {"e" , 3 , 4 }),
193+ "d BETWEEN ? AND ? AND e BETWEEN ? AND ?" ,
194+ []interface {}{0 , 2 , 3 , 4 },
195+ },
196+ {
197+ Between {"d" , 0 , 2 }.Or (Between {"e" , 3 , 4 }),
198+ "d BETWEEN ? AND ? OR e BETWEEN ? AND ?" ,
199+ []interface {}{0 , 2 , 3 , 4 },
200+ },
126201{
127202IsNull {"d" },
128203"d IS NULL" ,
129204[]interface {}{},
130205},
206+ {
207+ IsNull {"d" }.And (IsNull {"e" }),
208+ "d IS NULL AND e IS NULL" ,
209+ []interface {}{},
210+ },
211+ {
212+ IsNull {"d" }.Or (IsNull {"e" }),
213+ "d IS NULL OR e IS NULL" ,
214+ []interface {}{},
215+ },
216+ {
217+ NotNull {"d" },
218+ "d IS NOT NULL" ,
219+ []interface {}{},
220+ },
221+ {
222+ NotNull {"d" }.And (NotNull {"e" }),
223+ "d IS NOT NULL AND e IS NOT NULL" ,
224+ []interface {}{},
225+ },
226+ {
227+ NotNull {"d" }.Or (NotNull {"e" }),
228+ "d IS NOT NULL OR e IS NOT NULL" ,
229+ []interface {}{},
230+ },
131231{
132232NotIn ("a" , 1 , 2 ).And (NotIn ("b" , "c" , "d" )),
133233"a NOT IN (?,?) AND b NOT IN (?,?)" ,
@@ -388,6 +488,26 @@ func TestBuilderCond(t *testing.T) {
388488"NOT (a=? AND b=?)" ,
389489[]interface {}{1 , 2 },
390490},
491+ {
492+ Not {Eq {"a" : 1 }.And (Eq {"b" : 2 })},
493+ "NOT (a=? AND b=?)" ,
494+ []interface {}{1 , 2 },
495+ },
496+ {
497+ Not {Neq {"a" : 1 }.And (Neq {"b" : 2 })},
498+ "NOT (a<>? AND b<>?)" ,
499+ []interface {}{1 , 2 },
500+ },
501+ {
502+ Not {Eq {"a" : 1 }}.And (Neq {"b" : 2 }),
503+ "NOT a=? AND b<>?" ,
504+ []interface {}{1 , 2 },
505+ },
506+ {
507+ Not {Eq {"a" : 1 }}.Or (Neq {"b" : 2 }),
508+ "NOT a=? OR b<>?" ,
509+ []interface {}{1 , 2 },
510+ },
391511}
392512
393513for _ , k := range cases {
0 commit comments