sq/libsq/query_unique_test.go
Neil O'Toole f07edef14d
Add flag --src.schema (#326)
* Support for --src.schema in commands "slq", "sql", and "inspect"
2023-11-18 17:05:48 -07:00

60 lines
1.6 KiB
Go

package libsq_test
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{
{
name: "unique/single-col",
in: `@sakila | .actor | .first_name | unique`,
wantSQL: `SELECT DISTINCT "first_name" FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT `first_name` FROM `actor`"},
wantRecCount: 128,
},
{
name: "unique/no-col-with-parens",
in: `@sakila | .actor | unique()`,
wantSQL: `SELECT DISTINCT * FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
wantRecCount: sakila.TblActorCount,
},
{
name: "unique/no-col",
in: `@sakila | .actor | unique`,
wantSQL: `SELECT DISTINCT * FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
wantRecCount: sakila.TblActorCount,
},
{
name: "uniq/no-col",
in: `@sakila | .actor | uniq`,
wantSQL: `SELECT DISTINCT * FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
wantRecCount: sakila.TblActorCount,
},
{
name: "uniq/no-col-with-parens",
in: `@sakila | .actor | uniq()`,
wantSQL: `SELECT DISTINCT * FROM "actor"`,
override: driverMap{mysql.Type: "SELECT DISTINCT * FROM `actor`"},
wantRecCount: sakila.TblActorCount,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
execQueryTestCase(t, tc)
})
}
}