2023-04-01 12:48:24 +03:00
|
|
|
package libsq_test
|
2023-04-01 11:38:32 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-11-20 04:06:36 +03:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2023-04-01 11:38:32 +03:00
|
|
|
|
2024-01-25 09:29:55 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/source/drivertype"
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/testh/sakila"
|
2023-04-01 11:38:32 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
//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"`,
|
2024-01-25 09:29:55 +03:00
|
|
|
override: driverMap{drivertype.MySQL: "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-11-19 03:05:48 +03:00
|
|
|
name: "unique/no-col-with-parens",
|
|
|
|
in: `@sakila | .actor | unique()`,
|
2023-06-17 07:54:25 +03:00
|
|
|
wantSQL: `SELECT DISTINCT * FROM "actor"`,
|
2024-01-25 09:29:55 +03:00
|
|
|
override: driverMap{drivertype.MySQL: "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"`,
|
2024-01-25 09:29:55 +03:00
|
|
|
override: driverMap{drivertype.MySQL: "SELECT DISTINCT * FROM `actor`"},
|
2023-06-17 07:54:25 +03:00
|
|
|
wantRecCount: sakila.TblActorCount,
|
2023-04-01 11:38:32 +03:00
|
|
|
},
|
2023-11-19 03:05:48 +03:00
|
|
|
{
|
|
|
|
name: "uniq/no-col",
|
|
|
|
in: `@sakila | .actor | uniq`,
|
|
|
|
wantSQL: `SELECT DISTINCT * FROM "actor"`,
|
2024-01-25 09:29:55 +03:00
|
|
|
override: driverMap{drivertype.MySQL: "SELECT DISTINCT * FROM `actor`"},
|
2023-11-19 03:05:48 +03:00
|
|
|
wantRecCount: sakila.TblActorCount,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "uniq/no-col-with-parens",
|
|
|
|
in: `@sakila | .actor | uniq()`,
|
|
|
|
wantSQL: `SELECT DISTINCT * FROM "actor"`,
|
2024-01-25 09:29:55 +03:00
|
|
|
override: driverMap{drivertype.MySQL: "SELECT DISTINCT * FROM `actor`"},
|
2023-11-19 03:05:48 +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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|