2023-04-01 12:48:24 +03:00
|
|
|
package libsq_test
|
2023-04-01 11:38:32 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/neilotoole/sq/testh/sakila"
|
|
|
|
|
|
|
|
"github.com/neilotoole/sq/drivers/mysql"
|
|
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
|
|
|
//nolint:exhaustive
|
|
|
|
func TestQuery_unique(t *testing.T) {
|
|
|
|
testCases := []queryTestCase{
|
|
|
|
{
|
2023-06-17 07:54:25 +03:00
|
|
|
name: "unique/single-col",
|
|
|
|
in: `@sakila | .actor | .first_name | unique`,
|
|
|
|
wantSQL: `SELECT DISTINCT "first_name" FROM "actor"`,
|
2023-06-18 09:05:09 +03:00
|
|
|
override: driverMap{mysql.Type: "SELECT DISTINCT `first_name` FROM `actor`"},
|
2023-06-17 07:54:25 +03:00
|
|
|
wantRecCount: 128,
|
2023-04-01 11:38:32 +03:00
|
|
|
},
|
|
|
|
{
|
2023-06-17 07:54:25 +03:00
|
|
|
name: "unique/no-col",
|
|
|
|
in: `@sakila | .actor | unique`,
|
|
|
|
wantSQL: `SELECT DISTINCT * FROM "actor"`,
|
2023-06-18 09:05:09 +03:00
|
|
|
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
|
2023-06-17 07:54:25 +03:00
|
|
|
wantRecCount: sakila.TblActorCount,
|
2023-04-01 11:38:32 +03:00
|
|
|
},
|
|
|
|
{
|
2023-06-17 07:54:25 +03:00
|
|
|
name: "unique/no-col",
|
|
|
|
in: `@sakila | .actor | unique`,
|
|
|
|
wantSQL: `SELECT DISTINCT * FROM "actor"`,
|
2023-06-18 09:05:09 +03:00
|
|
|
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
|
2023-06-17 07:54:25 +03:00
|
|
|
wantRecCount: sakila.TblActorCount,
|
2023-04-01 11:38:32 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
execQueryTestCase(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|