-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.go
More file actions
40 lines (34 loc) · 915 Bytes
/
Copy pathfunctions.go
File metadata and controls
40 lines (34 loc) · 915 Bytes
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
package click
import (
"strings"
)
// popular SQL functions
func Fn(name string, args ...Expression) Expression {
return fnCall{
name: name,
args: args,
}
}
type fnCall struct {
name string
args []Expression
}
func (f fnCall) Expression() string {
var sb strings.Builder
sb.WriteString(f.name)
sb.WriteByte('(')
for i := range f.args {
if i != 0 {
sb.WriteString(", ")
}
sb.WriteString(f.args[i].Expression())
}
sb.WriteByte(')')
return sb.String()
}
func Sum(v Expression) Expression { return Fn("sum", v) }
func Avg(v Expression) Expression { return Fn("avg", v) }
func Count(v ...Expression) Expression { return Fn("count", v...) }
func CountIf(v Expression) Expression { return Fn("countIf", v) }
func If(cond, v1, v2 Expression) Expression { return Fn("if", cond, v1, v2) }
func IsNotNull(v Expression) Expression { return Fn("isNotNull", v) }