-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathfunction.go
More file actions
41 lines (34 loc) · 1.17 KB
/
function.go
File metadata and controls
41 lines (34 loc) · 1.17 KB
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
package sqlingo
func function(name string, args ...interface{}) expression {
return expression{builder: func(scope scope) (string, error) {
valuesSql, err := commaValues(scope, args)
if err != nil {
return "", err
}
return name + "(" + valuesSql + ")", nil
}}
}
// Function creates an expression of the call to specified function.
func Function(name string, args ...interface{}) UnknownExpression {
return function(name, args...)
}
// Concat creates an expression of CONCAT function.
func Concat(args ...interface{}) StringExpression {
return function("CONCAT", args...)
}
// Count creates an expression of COUNT aggregator.
func Count(arg interface{}) NumberExpression {
return function("COUNT", arg)
}
// If creates an expression of IF function.
func If(predicate Expression, trueValue interface{}, falseValue interface{}) (result UnknownExpression) {
return function("IF", predicate, trueValue, falseValue)
}
// Length creates an expression of LENGTH function.
func Length(arg interface{}) NumberExpression {
return function("LENGTH", arg)
}
// Sum creates an expression of SUM aggregator.
func Sum(arg interface{}) NumberExpression {
return function("SUM", arg)
}