Skip to content

Commit a93f903

Browse files
committed
offset limit使用int64参数,修改测试用例
1 parent 62ecd4e commit a93f903

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

builder/sql.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package builder
1111
import (
1212
"fmt"
1313
"strings"
14+
"strconv"
1415
)
1516

1617
type SQLFragment struct {
@@ -248,23 +249,23 @@ func (f *SQLFragment) Asc() *SQLFragment {
248249
return fragment
249250
}
250251

251-
func (f *SQLFragment) Offset(offset string) *SQLFragment {
252+
func (f *SQLFragment) Offset(offset int64) *SQLFragment {
252253
fragment := &SQLFragment{}
253254
fragment.initParent(f)
254255

255256
fragment.builder.WriteString("OFFSET ")
256-
fragment.builder.WriteString(offset)
257+
fragment.builder.WriteString(strconv.FormatInt(offset, 10))
257258
fragment.builder.WriteString(" ")
258259

259260
return fragment
260261
}
261262

262-
func (f *SQLFragment) Limit(limit string) *SQLFragment {
263+
func (f *SQLFragment) Limit(limit int64) *SQLFragment {
263264
fragment := &SQLFragment{}
264265
fragment.initParent(f)
265266

266267
fragment.builder.WriteString("LIMIT ")
267-
fragment.builder.WriteString(limit)
268+
fragment.builder.WriteString(strconv.FormatInt(limit, 10))
268269
fragment.builder.WriteString(" ")
269270

270271
return fragment

test/sqlbuilder_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,19 @@ func TestSqlBuilderSelect(t *testing.T) {
2121
}
2222
t.Run("once call", func(t *testing.T) {
2323
str := builder.Select("A.test1", "B.test2").
24-
Hook(hook).
2524
From("test_a").
26-
Hook(hook).
2725
Where("id = 1").
28-
Hook(hook).
2926
And().
30-
Hook(hook).
3127
Where("name=2").
32-
Hook(hook).
3328
GroupBy("name").
34-
Hook(hook).
3529
OrderBy("name").
36-
Hook(hook).
3730
Desc().
38-
Hook(hook).
31+
Offset(5).
32+
Limit(10).
3933
String()
4034
t.Log(str)
4135

42-
if strings.TrimSpace(str) != `SELECT A.test1, B.test2 FROM test_a WHERE id = 1 AND name=2 GROUP BY name ORDER BY name DESC` {
36+
if strings.TrimSpace(str) != `SELECT A.test1, B.test2 FROM test_a WHERE id = 1 AND name=2 GROUP BY name ORDER BY name DESC OFFSET 5 LIMIT 10` {
4337
t.FailNow()
4438
}
4539
})

0 commit comments

Comments
 (0)