@@ -3,7 +3,8 @@ module orm
3
3
import time
4
4
import strings.textscanner
5
5
6
- const operators = ['=' , '!=' , '<>' , '>=' , '<=' , '>' , '<' , 'LIKE' , 'ILIKE' , 'IS NULL' , 'IS NOT NULL' ]!
6
+ const operators = ['=' , '!=' , '<>' , '>=' , '<=' , '>' , '<' , 'LIKE' , 'ILIKE' , 'IS NULL' , 'IS NOT NULL' ,
7
+ 'IN' , 'NOT IN' ]!
7
8
8
9
@[heap]
9
10
pub struct QueryBuilder [T] {
@@ -45,7 +46,7 @@ pub fn (qb_ &QueryBuilder[T]) reset() &QueryBuilder[T] {
45
46
46
47
// where create a `where` clause, it will `AND` with previous `where` clause.
47
48
// valid token in the `condition` include: `field's names`, `operator`, `(`, `)`, `?`, `AND`, `OR`, `||`, `&&`,
48
- // valid `operator` incldue: `=`, `!=`, `<>`, `>=`, `<=`, `>`, `<`, `LIKE`, `ILIKE`, `IS NULL`, `IS NOT NULL`
49
+ // valid `operator` incldue: `=`, `!=`, `<>`, `>=`, `<=`, `>`, `<`, `LIKE`, `ILIKE`, `IS NULL`, `IS NOT NULL`, `IN`, `NOT IN`
49
50
// example: `where('(a > ? AND b <= ?) OR (c <> ? AND (x = ? OR y = ?))', a, b, c, x, y)`
50
51
pub fn (qb_ &QueryBuilder[T]) where (condition string , params ...Primitive) ! & QueryBuilder[T] {
51
52
mut qb := unsafe { qb_ }
@@ -102,9 +103,13 @@ fn (mut ss MyTextScanner) next_tok() string {
102
103
ss.pos + = 7
103
104
return 'IS NULL'
104
105
}
106
+ if ss.input[ss.pos..].starts_with ('NOT IN' ) {
107
+ ss.pos + = 6
108
+ return 'NOT IN'
109
+ }
105
110
if ss.remaining () > = 2 {
106
111
two_chars := ss.input[ss.pos..ss.pos + 2 ]
107
- if two_chars in ['>=' , '<=' , '<>' , '!=' , '||' , '&&' ] {
112
+ if two_chars in ['>=' , '<=' , '<>' , '!=' , '||' , '&&' , 'IN' ] {
108
113
ss.pos + = 2
109
114
return two_chars
110
115
}
@@ -215,6 +220,12 @@ fn (qb_ &QueryBuilder[T]) parse_conditions(conds string, params []Primitive) ! {
215
220
'IS NOT NULL' {
216
221
OperationKind.is_not_null
217
222
}
223
+ 'IN' {
224
+ OperationKind.in
225
+ }
226
+ 'NOT IN' {
227
+ OperationKind.not_in
228
+ }
218
229
else {
219
230
parse_error ('${@FN} (): unsupported operator: `${tok} `' , s.last_tok_start,
220
231
conds)!
0 commit comments