forked from chuckpreslar/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.go
More file actions
124 lines (102 loc) · 3.2 KB
/
function.go
File metadata and controls
124 lines (102 loc) · 3.2 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
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
package codex
// FunctionNode is a Nary node.
type FunctionNode struct {
Name string // MAX, COUNT, LOWER, AVG, ...
Args []interface{} //
// TODO remove
Alias interface{} // Alias the function result is reffered to as.
// TODO make Distinkt a Node without (); strange btw.
Distinct bool // Function is distinct.
}
// Returns and Equal node containing a reference to the
// function and other
func (f *FunctionNode) Eq(other interface{}) *EqualNode {
return Equal(f, other)
}
// Returns and NotEqual node containing a reference to the
// function and other
func (f *FunctionNode) Neq(other interface{}) *NotEqualNode {
return NotEqual(f, other)
}
// Returns and GreaterThan node containing a reference to the
// function and other
func (f *FunctionNode) Gt(other interface{}) *GreaterThanNode {
return GreaterThan(f, other)
}
// Returns and GreaterThanOrEqual node containing a reference to the
// function and other
func (f *FunctionNode) Gte(other interface{}) *GreaterThanOrEqualNode {
return GreaterThanOrEqual(f, other)
}
// Returns and LessThan node containing a reference to the
// function and other
func (f *FunctionNode) Lt(other interface{}) *LessThanNode {
return LessThan(f, other)
}
// Returns and LessThanOrEqual node containing a reference to the
// function and other
func (f *FunctionNode) Lte(other interface{}) *LessThanOrEqualNode {
return LessThanOrEqual(f, other)
}
// Returns and Like node containing a reference to the
// function and other
func (f *FunctionNode) Like(other interface{}) *LikeNode {
return Like(f, other)
}
// Returns and Unlike node containing a reference to the
// function and other
func (f *FunctionNode) Unlike(other interface{}) *UnlikeNode {
return Unlike(f, other)
}
// Returns and Or node containing a reference to the
// function and other
func (f *FunctionNode) Or(other interface{}) *GroupingNode {
return Grouping(Or(f, other))
}
// Returns and And node containing a reference to the
// function and other
func (f *FunctionNode) And(other interface{}) *GroupingNode {
return Grouping(And(f, other))
}
// As creates an alias e.g. vor selected cols e.g. "products"."id" AS "product_id"
// "product_id" would be the alias here
func (f *FunctionNode) As(alias interface{}) *AsNode {
if s, ok := alias.(string); ok {
alias = Column(s)
}
return As(f, alias)
}
// FunctionNode generic factory method.
func Function(name string, args ...interface{}) *FunctionNode {
return &FunctionNode{
Name: name,
Args: args,
}
}
func Avg(args ...interface{}) *FunctionNode {
return Function("AVG", args...)
}
func Coalesce(args ...interface{}) *FunctionNode {
return Function("COALESCE", args...)
}
func Count(args ...interface{}) *FunctionNode {
return Function("COUNT", args...)
}
func Max(args ...interface{}) *FunctionNode {
return Function("MAX", args...)
}
func Min(args ...interface{}) *FunctionNode {
return Function("MIN", args...)
}
func Sum(args ...interface{}) *FunctionNode {
return Function("SUM", args...)
}
func Lower(args ...interface{}) *FunctionNode {
return Function("LOWER", args...)
}
func Upper(args ...interface{}) *FunctionNode {
return Function("UPPER", args...)
}
func Substring(args ...interface{}) *FunctionNode {
return Function("SUBSTRING", args...)
}