-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.go
53 lines (42 loc) · 891 Bytes
/
logic.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
package gormqy
import (
"fmt"
"strings"
)
const (
LogicAnd = "AND"
LogicOr = "OR"
)
type Logic struct {
cond *Condition
}
func (l *Logic) And() *Condition {
l.cond.exprs = append(l.cond.exprs, LogicAnd)
return l.cond
}
func (l *Logic) Or() *Condition {
l.cond.exprs = append(l.cond.exprs, LogicOr)
return l.cond
}
func (l *Logic) End() *Query {
return l.end(false)
}
func (l *Logic) EndWithGroup() *Query {
return l.end(true)
}
func (l *Logic) WithRightBracket() *Logic {
l.cond.withRightBracket()
return l
}
func (l *Logic) end(group bool) *Query {
if len(l.cond.exprs) == 0 {
return l.cond.query
}
expr := fmt.Sprintf("%s", strings.Join(l.cond.exprs, " "))
if group {
expr = "(" + expr + ")"
}
l.cond.query.whereExprs = append(l.cond.query.whereExprs, expr)
l.cond.query.whereVals = append(l.cond.query.whereVals, l.cond.vals...)
return l.cond.query
}