-
Notifications
You must be signed in to change notification settings - Fork 1
/
group_by.go
42 lines (31 loc) · 881 Bytes
/
group_by.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 nqb
import "bytes"
type GroupByClause interface {
SelectResult
// GroupBy adds a GROUP BY clause.
GroupBy(identifiers ...interface{}) LettingClause
}
type defaultGroupByClause struct {
*defaultSelectResult
}
func newDefaultGroupByClause(parent Statement) *defaultGroupByClause {
return &defaultGroupByClause{newDefaultSelectResult(parent)}
}
func (c *defaultGroupByClause) GroupBy(identifiers ...interface{}) LettingClause {
c.setElement(&groupByElement{toExpressions(identifiers...)})
return newDefaultLettingClause(c)
}
type groupByElement struct {
expressions []*Expression
}
func (e *groupByElement) export() string {
buf := bytes.NewBufferString("GROUP BY ")
for i, expression := range e.expressions {
buf.WriteString(expression.String())
// todo improve?
if i < len(e.expressions)-1 {
buf.WriteString(", ")
}
}
return buf.String()
}