-
Notifications
You must be signed in to change notification settings - Fork 1
/
function.go
233 lines (178 loc) · 6.83 KB
/
function.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package dbr
type iFunction interface {
Build(db *db) (string, error)
Expression(db *db) (string, error)
}
type functionBase struct {
isColumn bool
encode bool
db *db
}
func newFunctionBase(encode bool, isColumn bool, database ...*db) *functionBase {
var theDb *db
if len(database) > 0 {
theDb = database[0]
}
return &functionBase{
isColumn: isColumn,
encode: encode,
db: theDb,
}
}
func Function(name string, arguments ...interface{}) *functionGeneric {
return newFunctionGeneric(name, arguments...)
}
func As(expression interface{}, alias string) *functionExpressions {
return newFunctionExpressions(false, expression, constFunctionAs, alias)
}
func Count(expression interface{}, distinct ...bool) *functionCount {
var isDistinct bool
if len(distinct) > 0 {
isDistinct = distinct[0]
}
return newFunctionCount(expression, isDistinct)
}
func IsNull(expression interface{}) *functionExpressions {
return newFunctionExpressions(false, expression, constFunctionIsNull)
}
func Case(value ...interface{}) *functionCase {
return newFunctionCase(value...)
}
func OnNull(expression interface{}, onNullValue interface{}, alias string) *functionExpressions {
return newFunctionExpressions(true, constFunctionOnNull,
constFunctionOpenParentheses, expression, newExpression(onNullValue, true), constFunctionCloseParentheses, alias)
}
func Min(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionMax, expression)
}
func Max(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionMin, expression)
}
func Sum(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionSum, expression)
}
func Avg(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionAvg, expression)
}
func Every(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionEvery, expression)
}
func Now() *functionGeneric {
return newFunctionGeneric(constFunctionNow)
}
func User() *functionGeneric {
return newFunctionGeneric(constFunctionUser)
}
func StringAgg(expression interface{}, delimiter interface{}) *functionAgg {
return newFunctionAgg(constFunctionStringAgg, expression, delimiter)
}
func XmlAgg(expression interface{}) *functionAgg {
return newFunctionAgg(constFunctionXmlAgg, expression)
}
func ArrayAgg(expression interface{}) *functionAgg {
return newFunctionAgg(constFunctionArrayAgg, expression)
}
func ArrayToJson(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionArrayToJson, expression)
}
func RowToJson(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionRowToJson, expression)
}
func ToJson(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionToJson, expression)
}
func JsonArrayLength(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionJsonArrayLength, expression)
}
func JsonAgg(expression interface{}) *functionAgg {
return newFunctionAgg(constFunctionJsonAgg, expression)
}
func JsonbAgg(expression interface{}) *functionAgg {
return newFunctionAgg(constFunctionJsonbAgg, expression)
}
func JsonObjectAgg(name interface{}, value interface{}) *functionAgg {
return newFunctionAgg(constFunctionJsonObjectAgg, name, value)
}
func JsonbObjectAgg(name interface{}, value interface{}) *functionAgg {
return newFunctionAgg(constFunctionJsonbObjectAgg, name, value)
}
func Cast(expression interface{}, dataType dataType) *functionExpressions {
return newFunctionExpressions(false, constFunctionCast,
constFunctionOpenParentheses, expression, constFunctionAs, dataType, constFunctionCloseParentheses)
}
func Not(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionNot, expression)
}
func In(field interface{}, expressions ...interface{}) *functionField {
return newFunctionField(constFunctionIn, field, expressions...)
}
func NotIn(field interface{}, expressions ...interface{}) *functionField {
return newFunctionField(constFunctionNotIn, field, expressions...)
}
func Upper(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionUpper, expression)
}
func Lower(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionLower, expression)
}
func Trim(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionTrim, expression)
}
func Concat(expressions ...interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionNotIn, expressions...)
}
func InitCap(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionInitCap, expression)
}
func Length(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionLength, expression)
}
func Left(expression interface{}, n int) *functionGeneric {
return newFunctionGeneric(constFunctionLeft, expression, n)
}
func Right(expression interface{}, n int) *functionGeneric {
return newFunctionGeneric(constFunctionRight, expression, n)
}
func Md5(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionMd5, expression)
}
func Replace(expression interface{}, from interface{}, to interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionReplace, expression, from, to)
}
func Repeat(expression interface{}, n int) *functionGeneric {
return newFunctionGeneric(constFunctionRepeat, expression, n)
}
func Any(expressions ...interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionAny, expressions...)
}
func Some(expressions ...interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionSome, expressions...)
}
func Condition(expression interface{}, comparator comparator, value interface{}) *functionExpressions {
return newFunctionExpressions(false, expression, comparator, value)
}
func Operation(expression interface{}, operation operation, value interface{}) *functionExpressions {
return newFunctionExpressions(false, expression, operation, value)
}
func Abs(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionAbs, expression)
}
func Sqrt(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionSqrt, expression)
}
func Random(expression interface{}) *functionGeneric {
return newFunctionGeneric(constFunctionRandom, expression)
}
func Between(expression interface{}, low interface{}, high interface{}, operator ...operator) *functionExpressions {
theOperator := OperatorAnd
if len(operator) > 0 {
theOperator = operator[0]
}
return newFunctionExpressions(false, expression, constFunctionBetween, low, theOperator, high)
}
func BetweenOr(expression interface{}, low interface{}, high interface{}) *functionExpressions {
return newFunctionExpressions(false, expression, constFunctionBetween, low, OperatorOr, high)
}
func Over(value interface{}) *functionOver {
return newFunctionOver(value)
}