File tree Expand file tree Collapse file tree 2 files changed +8
-13
lines changed Expand file tree Collapse file tree 2 files changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ package builder
11
11
import (
12
12
"fmt"
13
13
"strings"
14
+ "strconv"
14
15
)
15
16
16
17
type SQLFragment struct {
@@ -248,23 +249,23 @@ func (f *SQLFragment) Asc() *SQLFragment {
248
249
return fragment
249
250
}
250
251
251
- func (f * SQLFragment ) Offset (offset string ) * SQLFragment {
252
+ func (f * SQLFragment ) Offset (offset int64 ) * SQLFragment {
252
253
fragment := & SQLFragment {}
253
254
fragment .initParent (f )
254
255
255
256
fragment .builder .WriteString ("OFFSET " )
256
- fragment .builder .WriteString (offset )
257
+ fragment .builder .WriteString (strconv . FormatInt ( offset , 10 ) )
257
258
fragment .builder .WriteString (" " )
258
259
259
260
return fragment
260
261
}
261
262
262
- func (f * SQLFragment ) Limit (limit string ) * SQLFragment {
263
+ func (f * SQLFragment ) Limit (limit int64 ) * SQLFragment {
263
264
fragment := & SQLFragment {}
264
265
fragment .initParent (f )
265
266
266
267
fragment .builder .WriteString ("LIMIT " )
267
- fragment .builder .WriteString (limit )
268
+ fragment .builder .WriteString (strconv . FormatInt ( limit , 10 ) )
268
269
fragment .builder .WriteString (" " )
269
270
270
271
return fragment
Original file line number Diff line number Diff line change @@ -21,25 +21,19 @@ func TestSqlBuilderSelect(t *testing.T) {
21
21
}
22
22
t .Run ("once call" , func (t * testing.T ) {
23
23
str := builder .Select ("A.test1" , "B.test2" ).
24
- Hook (hook ).
25
24
From ("test_a" ).
26
- Hook (hook ).
27
25
Where ("id = 1" ).
28
- Hook (hook ).
29
26
And ().
30
- Hook (hook ).
31
27
Where ("name=2" ).
32
- Hook (hook ).
33
28
GroupBy ("name" ).
34
- Hook (hook ).
35
29
OrderBy ("name" ).
36
- Hook (hook ).
37
30
Desc ().
38
- Hook (hook ).
31
+ Offset (5 ).
32
+ Limit (10 ).
39
33
String ()
40
34
t .Log (str )
41
35
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 ` {
43
37
t .FailNow ()
44
38
}
45
39
})
You can’t perform that action at this time.
0 commit comments