-
Notifications
You must be signed in to change notification settings - Fork 2
/
condition.go
147 lines (124 loc) · 2.29 KB
/
condition.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package clause
type Terms struct {
Column string
Values []interface{}
}
// GetTag get tag
func (t *Terms) GetTag() string {
return "terms"
}
// Set set value
func (t *Terms) Set(column string, values ...interface{}) {
t.Column = column
t.Values = values
}
type Match struct {
Column string
Values interface{}
}
// GetTag get tag
func (m *Match) GetTag() string {
return "match"
}
// Set set value
func (m *Match) Set(column string, values ...interface{}) {
var checkString = func(value interface{}) bool {
_, ok := value.(string)
return ok
}
m.Column = column
if len(values) != 1 || !checkString(values[0]) {
m.Values = "NULL"
} else {
m.Values = values[0]
}
}
type Term struct {
Column string
Values []interface{}
}
// GetTag get tag
func (t *Term) GetTag() string {
return "term"
}
// Set set value
func (t *Term) Set(column string, values ...interface{}) {
t.Column = column
t.Values = values
}
type conditionOP struct {
Column string
Values interface{}
}
// CSet set value
func (c *conditionOP) CSet(column string, values interface{}) {
c.Column = column
if values == nil {
values = "NULL"
}
c.Values = values
}
// LT less than
type LT struct {
conditionOP
}
// GetTag get tag
func (lt *LT) GetTag() string {
return "lt"
}
// Set set value
func (lt *LT) Set(column string, values ...interface{}) {
var value interface{}
if len(values) > 0 {
value = values[0]
}
lt.CSet(column, value)
}
// LTE less than or equal
type LTE struct {
conditionOP
}
// GetTag get tag
func (lte *LTE) GetTag() string {
return "lte"
}
// Set set value
func (lte *LTE) Set(column string, values ...interface{}) {
var value interface{}
if len(values) > 0 {
value = values[0]
}
lte.CSet(column, value)
}
// GT greater than
type GT struct {
conditionOP
}
// GetTag get tag
func (gt *GT) GetTag() string {
return "gt"
}
// Set set value
func (gt *GT) Set(column string, values ...interface{}) {
var value interface{}
if len(values) > 0 {
value = values[0]
}
gt.CSet(column, value)
}
// GTE greater than or equal
type GTE struct {
conditionOP
}
// GetTag get tag
func (gte *GTE) GetTag() string {
return "gte"
}
// Set set value
func (gte *GTE) Set(column string, values ...interface{}) {
var value interface{}
if len(values) > 0 {
value = values[0]
}
gte.CSet(column, value)
}