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/drivers/mysql"
|
|
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
2023-06-18 09:05:09 +03:00
|
|
|
//nolint:exhaustive
|
2023-04-01 11:38:32 +03:00
|
|
|
func TestQuery_args(t *testing.T) {
|
|
|
|
testCases := []queryTestCase{
|
|
|
|
{
|
2023-06-17 07:54:25 +03:00
|
|
|
name: "arg_value_string",
|
|
|
|
in: `@sakila | .actor | where(.first_name == $first)`,
|
|
|
|
args: map[string]string{"first": "TOM"},
|
|
|
|
wantSQL: `SELECT * FROM "actor" WHERE "first_name" = 'TOM'`,
|
2023-06-18 09:05:09 +03:00
|
|
|
override: driverMap{mysql.Type: "SELECT * FROM `actor` WHERE `first_name` = 'TOM'"},
|
2023-06-17 07:54:25 +03:00
|
|
|
wantRecCount: 2,
|
2023-04-07 11:00:49 +03:00
|
|
|
},
|
|
|
|
{
|
2023-06-17 07:54:25 +03:00
|
|
|
name: "arg_value_string_2",
|
|
|
|
in: `@sakila | .actor | where(.first_name == $first && .last_name == $last)`,
|
|
|
|
args: map[string]string{"first": "TOM", "last": "MIRANDA"},
|
|
|
|
wantSQL: `SELECT * FROM "actor" WHERE "first_name" = 'TOM' AND "last_name" = 'MIRANDA'`,
|
2023-06-18 09:05:09 +03:00
|
|
|
override: driverMap{mysql.Type: "SELECT * FROM `actor` WHERE `first_name` = 'TOM' AND `last_name` = 'MIRANDA'"},
|
2023-06-17 07:54:25 +03:00
|
|
|
wantRecCount: 1,
|
2023-04-07 11:00:49 +03:00
|
|
|
},
|
|
|
|
{
|
2023-06-17 07:54:25 +03:00
|
|
|
name: "arg_value_int",
|
|
|
|
in: `@sakila | .actor | where(.actor_id == int($id))`,
|
|
|
|
args: map[string]string{"id": "1"},
|
|
|
|
wantSQL: `SELECT * FROM "actor" WHERE "actor_id" = 1`,
|
2023-06-18 09:05:09 +03:00
|
|
|
override: driverMap{mysql.Type: "SELECT * FROM `actor` WHERE `actor_id` = 1"},
|
2023-06-17 07:54:25 +03:00
|
|
|
skip: true, // Skip until we implement casting, e.g. .actor_id == int($id)
|
|
|
|
wantRecCount: 1,
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|