-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregate.go
78 lines (70 loc) · 1.19 KB
/
aggregate.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
package morm
// Aggregate 聚合函数:AVG, MAX, MIN ...
type Aggregate struct {
fn string // 函数
arg string // 参数
alias string // 别名
table TableReference
}
func (a Aggregate) fieldName() string {
return a.arg
}
func (a Aggregate) target() TableReference {
return a.table
}
func (a Aggregate) selectedAlias() string {
return a.alias
}
func (Aggregate) expr() {}
func (a Aggregate) As(alias string) Aggregate {
return Aggregate{
fn: a.fn,
arg: a.arg,
alias: alias,
}
}
func (a Aggregate) EQ(arg any) Predicate { // = 等于
return Predicate{
left: a,
opt: optEQ,
right: exprOf(arg),
}
}
func (a Aggregate) LT(arg any) Predicate { // < 小于
return Predicate{
left: a,
opt: optLT,
right: exprOf(arg),
}
}
func (a Aggregate) GT(arg any) Predicate { // > 大于
return Predicate{
left: a,
opt: optGT,
right: exprOf(arg),
}
}
func Avg(c string) Aggregate {
return Aggregate{
fn: "AVG",
arg: c,
}
}
func Max(c string) Aggregate {
return Aggregate{
fn: "MAX",
arg: c,
}
}
func Count(c string) Aggregate {
return Aggregate{
fn: "COUNT",
arg: c,
}
}
func Sum(c string) Aggregate {
return Aggregate{
fn: "SUM",
arg: c,
}
}