forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
aggregate.go
42 lines (34 loc) · 1.14 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
package qb
// Avg function generates "avg(%s)" statement for clause
func Avg(clause Clause) AggregateClause {
return Aggregate("AVG", clause)
}
// Count function generates "count(%s)" statement for clause
func Count(clause Clause) AggregateClause {
return Aggregate("COUNT", clause)
}
// Sum function generates "sum(%s)" statement for clause
func Sum(clause Clause) AggregateClause {
return Aggregate("SUM", clause)
}
// Min function generates "min(%s)" statement for clause
func Min(clause Clause) AggregateClause {
return Aggregate("MIN", clause)
}
// Max function generates "max(%s)" statement for clause
func Max(clause Clause) AggregateClause {
return Aggregate("MAX", clause)
}
// Aggregate generates a new aggregate clause given function & clause
func Aggregate(fn string, clause Clause) AggregateClause {
return AggregateClause{fn, clause}
}
// AggregateClause is the base struct for building aggregate functions
type AggregateClause struct {
fn string
clause Clause
}
// Accept calls the compiler VisitAggregate function
func (c AggregateClause) Accept(context Context) string {
return context.Compiler().VisitAggregate(context, c)
}