-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgroupby.go
45 lines (36 loc) · 995 Bytes
/
groupby.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
package sqlbuilder
import (
"bytes"
)
//
// Author: 陈永佳 [email protected], [email protected]
//
type GroupByBuilder struct {
ctx *SQLContext
buffer *bytes.Buffer
}
func newGroupByBuilder(ctx *SQLContext, pre string, columns ...string) *GroupByBuilder {
gbb := &GroupByBuilder{
ctx: ctx,
buffer: new(bytes.Buffer),
}
gbb.buffer.WriteString(pre)
gbb.buffer.WriteString(" GROUP BY ")
gbb.buffer.WriteString(ctx.joinNames(columns))
return gbb
}
func (slf *GroupByBuilder) Compile() string {
return slf.buffer.String()
}
func (slf *GroupByBuilder) ToSQL() string {
return sqlEndpoint(slf.buffer)
}
func (slf *GroupByBuilder) Limit(limit int) *LimitBuilder {
return newLimitBuilder(slf.ctx, slf.Compile(), limit)
}
func (slf *GroupByBuilder) OrderBy(columns ...string) *OrderByBuilder {
return newOrderByBuilder(slf.ctx, slf.Compile(), columns...)
}
func (slf *GroupByBuilder) Execute() *Executor {
return newExecute(slf.ToSQL(), slf.ctx.prepare)
}