-
Notifications
You must be signed in to change notification settings - Fork 0
/
expression.go
94 lines (77 loc) · 1.34 KB
/
expression.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
88
89
90
91
92
93
94
package morm
// RawExpr 原生表达式,不做任何处理
type RawExpr struct {
raw string
args []interface{}
}
func (e RawExpr) fieldName() string {
return ""
}
func (e RawExpr) target() TableReference {
return nil
}
func (e RawExpr) selectedAlias() string {
return ""
}
func (e RawExpr) expr() {
}
func (e RawExpr) AsPredicate() Predicate {
return Predicate{
left: e,
}
}
func Raw(expr string, args ...interface{}) RawExpr {
return RawExpr{
raw: expr,
args: args,
}
}
type binaryExpr struct {
left Expression
opt opt
right Expression
}
func (b binaryExpr) expr() {
}
type MathExpr binaryExpr
func (m MathExpr) expr() {
}
func (m MathExpr) Add(val interface{}) MathExpr {
return MathExpr{
left: m,
opt: optADD,
right: valueOf(val),
}
}
func (m MathExpr) Multi(val interface{}) MathExpr {
return MathExpr{
left: m,
opt: optMULTI,
right: valueOf(val),
}
}
// SubqueryExpr 这个谓词这种不是在所有的数据库里面都支持的
type SubqueryExpr struct {
s Subquery
pred string
}
func (s SubqueryExpr) expr() {
}
func Any(sub Subquery) SubqueryExpr {
return SubqueryExpr{
s: sub,
pred: "ANY",
}
}
func All(sub Subquery) SubqueryExpr {
return SubqueryExpr{
s: sub,
pred: "ALL",
}
}
func Some(sub Subquery) SubqueryExpr {
return SubqueryExpr{
s: sub,
pred: "SOME",
}
}