mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-26 01:34:43 +03:00
2ba633fc2a
* Fixed space issues with expressions * Alias can now be an arbitrary string * Alias can now be an arbitrary string (fixed) * Alias now automatically applied to expressions * Ignore .run * Fixed issue with TestRun not logging correctly to testing.T * Fiddling with sqlite3 temp file closing * Re-enable tests
46 lines
1.6 KiB
Go
46 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,lll
|
|
func TestQuery_join(t *testing.T) {
|
|
testCases := []queryTestCase{
|
|
{
|
|
name: "join/single-selector",
|
|
in: `@sakila | .actor, .film_actor | join(.actor_id)`,
|
|
wantSQL: `SELECT * FROM "actor" INNER JOIN "film_actor" ON "actor"."actor_id" = "film_actor"."actor_id"`,
|
|
override: driverMap{mysql.Type: "SELECT * FROM `actor` INNER JOIN `film_actor` ON `actor`.`actor_id` = `film_actor`.`actor_id`"},
|
|
wantRecCount: sakila.TblFilmActorCount,
|
|
},
|
|
{
|
|
name: "join/fq-table-cols-equal",
|
|
in: `@sakila | .actor, .film_actor | join(.film_actor.actor_id == .actor.actor_id)`,
|
|
wantSQL: `SELECT * FROM "actor" INNER JOIN "film_actor" ON "film_actor"."actor_id" = "actor"."actor_id"`,
|
|
override: driverMap{mysql.Type: "SELECT * FROM `actor` INNER JOIN `film_actor` ON `film_actor`.`actor_id` = `actor`.`actor_id`"},
|
|
wantRecCount: sakila.TblFilmActorCount,
|
|
},
|
|
{
|
|
name: "join/fq-table-cols-equal-whitespace",
|
|
in: `@sakila | .actor, ."film actor" | join(."film actor".actor_id == .actor.actor_id)`,
|
|
wantSQL: `SELECT * FROM "actor" INNER JOIN "film actor" ON "film actor"."actor_id" = "actor"."actor_id"`,
|
|
override: driverMap{mysql.Type: "SELECT * FROM `actor` INNER JOIN `film actor` ON `film actor`.`actor_id` = `actor`.`actor_id`"},
|
|
skipExec: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
execQueryTestCase(t, tc)
|
|
})
|
|
}
|
|
}
|