github.com/eden-framework/sqlx@v0.0.2/builder/addition_limit_test.go (about) 1 package builder_test 2 3 import ( 4 "testing" 5 6 . "github.com/eden-framework/sqlx/builder" 7 . "github.com/eden-framework/sqlx/builder/buidertestingutils" 8 "github.com/onsi/gomega" 9 ) 10 11 func TestLimit(t *testing.T) { 12 table := T("T") 13 14 t.Run("select limit", func(t *testing.T) { 15 gomega.NewWithT(t).Expect( 16 Select(nil). 17 From( 18 table, 19 Where( 20 Col("F_a").Eq(1), 21 ), 22 Limit(1), 23 ), 24 ).To(BeExpr(` 25 SELECT * FROM T 26 WHERE f_a = ? 27 LIMIT 1 28 `, 1)) 29 }) 30 t.Run("select without limit", func(t *testing.T) { 31 gomega.NewWithT(t).Expect( 32 Select(nil). 33 From( 34 table, 35 Where( 36 Col("F_a").Eq(1), 37 ), 38 Limit(-1), 39 ), 40 ).To(BeExpr(` 41 SELECT * FROM T 42 WHERE f_a = ? 43 `, 1, 44 )) 45 }) 46 t.Run("select limit and offset", func(t *testing.T) { 47 gomega.NewWithT(t).Expect( 48 Select(nil). 49 From( 50 table, 51 Where( 52 Col("F_a").Eq(1), 53 ), 54 Limit(1).Offset(200), 55 ), 56 ).To(BeExpr(` 57 SELECT * FROM T 58 WHERE f_a = ? 59 LIMIT 1 OFFSET 200 60 `, 61 1, 62 )) 63 }) 64 }