-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathwhere.go
36 lines (31 loc) · 938 Bytes
/
where.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package qb
// Where generates a compilable where clause
func Where(clauses ...Clause) WhereClause {
var clause Clause
if len(clauses) == 1 {
clause = clauses[0]
} else {
clause = And(clauses...)
}
return WhereClause{clause}
}
// WhereClause is the base of any where clause when using expression api
type WhereClause struct {
clause Clause
}
// Accept compiles the where clause, returns sql
func (c WhereClause) Accept(context *CompilerContext) string {
return context.Compiler.VisitWhere(context, c)
}
// And combine the current clause and the new ones with a And()
func (c WhereClause) And(clauses ...Clause) WhereClause {
clauses = append([]Clause{c.clause}, clauses...)
c.clause = And(clauses...)
return c
}
// Or combine the current clause and the new ones with a Or()
func (c WhereClause) Or(clauses ...Clause) WhereClause {
clauses = append([]Clause{c.clause}, clauses...)
c.clause = Or(clauses...)
return c
}