@@ -43,12 +43,28 @@ pub fn (qb_ &QueryBuilder[T]) reset() &QueryBuilder[T] {
4343 return qb
4444}
4545
46- // where create a `where` clause
46+ // where create a `where` clause, it will `AND` with previous `where` clause.
4747// valid token in the `condition` include: `field's names`, `operator`, `(`, `)`, `?`, `AND`, `OR`, `||`, `&&`,
4848// valid `operator` incldue: `=`, `!=`, `<>`, `>=`, `<=`, `>`, `<`, `LIKE`, `ILIKE`, `IS NULL`, `IS NOT NULL`
4949// example: `where('(a > ? AND b <= ?) OR (c <> ? AND (x = ? OR y = ?))', a, b, c, x, y)`
5050pub fn (qb_ &QueryBuilder[T]) where (condition string , params ...Primitive) ! & QueryBuilder[T] {
5151 mut qb := unsafe { qb_ }
52+ if qb.where.fields.len > 0 {
53+ // skip first field
54+ qb.where.is_and << true // and
55+ }
56+ qb.parse_conditions (condition, params)!
57+ qb.config.has_where = true
58+ return qb
59+ }
60+
61+ // or_where create a `where` clause, it will `OR` with previous `where` clause.
62+ pub fn (qb_ &QueryBuilder[T]) or_where (condition string , params ...Primitive) ! & QueryBuilder[T] {
63+ mut qb := unsafe { qb_ }
64+ if qb.where.fields.len > 0 {
65+ // skip first field
66+ qb.where.is_and << false // or
67+ }
5268 qb.parse_conditions (condition, params)!
5369 qb.config.has_where = true
5470 return qb
0 commit comments