github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/sqx/count_test.go (about) 1 package sqx_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/bingoohuang/gg/pkg/sqx" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func ExampleCreateCount() { 12 ret, err := sqx.SQL{ 13 Q: `select a, b, c from t where a = ? and b = ? order by a limit ?, ?`, 14 Vars: []interface{}{"地球", "亚洲", 0, 100}, 15 }.CreateCount() 16 fmt.Println(fmt.Sprintf("%+v", ret), err) 17 18 // Output: 19 // &{Name: Q:select count(*) from t where a = ? and b = ? Vars:[地球 亚洲] Ctx:<nil> NoLog:false Timeout:0s Limit:0 ConvertOptions:[] adapted:false} <nil> 20 } 21 22 func TestCreateCount(t *testing.T) { 23 s := &sqx.SQL{ 24 Q: `select a,b,c from t order by a`, 25 } 26 27 c, err := s.CreateCount() 28 assert.Nil(t, err) 29 assert.Equal(t, `select count(*) from t`, c.Q) 30 assert.Nil(t, c.Vars) 31 }