-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlimit.go
52 lines (42 loc) · 1.12 KB
/
limit.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
package sqlbuilder
import (
"bytes"
"strconv"
)
//
// Author: 陈永佳 [email protected], [email protected]
//
type LimitBuilder struct {
ctx *SQLContext
buffer *bytes.Buffer
}
func newLimitBuilder(ctx *SQLContext, pre string, limit int) *LimitBuilder {
lb := &LimitBuilder{
ctx: ctx,
buffer: new(bytes.Buffer),
}
lb.buffer.WriteString(pre)
lb.buffer.WriteString(" LIMIT ")
lb.buffer.WriteString(strconv.Itoa(limit))
return lb
}
func (slf *LimitBuilder) Offset(offset int) *LimitBuilder {
slf.buffer.WriteString(" OFFSET ")
slf.buffer.WriteString(strconv.Itoa(offset))
return slf
}
func (slf *LimitBuilder) Compile() string {
return slf.buffer.String()
}
func (slf *LimitBuilder) ToSQL() string {
return sqlEndpoint(slf.buffer)
}
func (slf *LimitBuilder) OrderBy(columns ...string) *OrderByBuilder {
return newOrderByBuilder(slf.ctx, slf.Compile(), columns...)
}
func (slf *LimitBuilder) GroupBy(columns ...string) *GroupByBuilder {
return newGroupByBuilder(slf.ctx, slf.Compile(), columns...)
}
func (slf *LimitBuilder) Execute() *Executor {
return newExecute(slf.ToSQL(), slf.ctx.prepare)
}