-
Notifications
You must be signed in to change notification settings - Fork 26
/
conditional.go
87 lines (72 loc) · 2.58 KB
/
conditional.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package qb
// conditional generators, comparator functions
// Like generates a like conditional sql clause
func Like(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, "LIKE", GetClauseFrom(right))
}
// In generates an IN conditional sql clause
func In(left Clause, values ...interface{}) InClause {
return InClause{BinaryExpressionClause{
Left: left,
Op: "IN",
Right: GetListFrom(values...),
}}
}
// NotIn generates an NOT IN conditional sql clause
func NotIn(left Clause, values ...interface{}) InClause {
return InClause{BinaryExpressionClause{
Left: left,
Op: "NOT IN",
Right: GetListFrom(values...),
}}
}
// NotEq generates a not equal conditional sql clause
func NotEq(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, "!=", GetClauseFrom(right))
}
// Eq generates a equals conditional sql clause
func Eq(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, "=", GetClauseFrom(right))
}
// Gt generates a greater than conditional sql clause
func Gt(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, ">", GetClauseFrom(right))
}
// Lt generates a less than conditional sql clause
func Lt(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, "<", GetClauseFrom(right))
}
// Gte generates a greater than or equal to conditional sql clause
func Gte(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, ">=", GetClauseFrom(right))
}
// Lte generates a less than or equal to conditional sql clause
func Lte(left Clause, right interface{}) BinaryExpressionClause {
return BinaryExpression(left, "<=", GetClauseFrom(right))
}
// BinaryExpression generates a condition object to use in update, delete & select statements
func BinaryExpression(left Clause, op string, right Clause) BinaryExpressionClause {
return BinaryExpressionClause{
Left: left,
Right: right,
Op: op,
}
}
// BinaryExpressionClause is the base struct for any conditional statements in sql clauses
type BinaryExpressionClause struct {
Left Clause
Right Clause
Op string
}
// Accept calls the compiler VisitBinary method
func (c BinaryExpressionClause) Accept(context *CompilerContext) string {
return context.Compiler.VisitBinary(context, c)
}
// InClause is a IN or NOT IN binary expression
type InClause struct {
BinaryExpressionClause
}
// Accept calls the compiler VisitBinary method
func (c InClause) Accept(context *CompilerContext) string {
return context.Compiler.VisitIn(context, c)
}