gitee.com/eden-framework/sqlx@v0.0.3/builder/stmt_select_test.go (about) 1 package builder_test 2 3 import ( 4 "testing" 5 6 . "gitee.com/eden-framework/sqlx/builder" 7 . "gitee.com/eden-framework/sqlx/builder/buidertestingutils" 8 "github.com/onsi/gomega" 9 ) 10 11 func TestSelect(t *testing.T) { 12 table := T("T") 13 14 t.Run("select with modifier", func(t *testing.T) { 15 gomega.NewWithT(t).Expect( 16 Select(nil, "DISTINCT"). 17 From( 18 table, 19 Where( 20 Col("F_a").Eq(1), 21 ), 22 ), 23 ).To(BeExpr(` 24 SELECT DISTINCT * FROM T 25 WHERE f_a = ?`, 1)) 26 }) 27 t.Run("select simple", func(t *testing.T) { 28 gomega.NewWithT(t).Expect( 29 Select(nil). 30 From( 31 table, 32 Where( 33 Col("F_a").Eq(1), 34 ), 35 Comment("comment"), 36 ), 37 ).To(BeExpr(` 38 SELECT * FROM T 39 WHERE f_a = ? 40 /* comment */ 41 `, 1)) 42 }) 43 t.Run("select with target", func(t *testing.T) { 44 gomega.NewWithT(t).Expect( 45 Select(Col("F_a")). 46 From(table, 47 Where( 48 Col("F_a").Eq(1), 49 ), 50 ), 51 ).To(BeExpr(` 52 SELECT f_a FROM T 53 WHERE f_a = ?`, 1)) 54 }) 55 t.Run("select for update", func(t *testing.T) { 56 gomega.NewWithT(t).Expect( 57 Select(nil).From( 58 table, 59 Where(Col("F_a").Eq(1)), 60 ForUpdate(), 61 ), 62 ).To(BeExpr( 63 ` 64 SELECT * FROM T 65 WHERE f_a = ? 66 FOR UPDATE 67 `, 68 1, 69 )) 70 }) 71 }