MySQL expression operators tests.
This commit is contained in:
parent
c342f296ca
commit
dfb72c06a7
4 changed files with 136 additions and 6 deletions
|
|
@ -27,6 +27,67 @@ func TestAllTypes(t *testing.T) {
|
|||
testutils.AssertJSON(t, dest, allTypesJson)
|
||||
}
|
||||
|
||||
func TestExpressionOperators(t *testing.T) {
|
||||
query := AllTypes.SELECT(
|
||||
AllTypes.Integer.IS_NULL().AS("result.is_null"),
|
||||
AllTypes.DatePtr.IS_NOT_NULL().AS("result.is_not_null"),
|
||||
AllTypes.SmallIntPtr.IN(Int(11), Int(22)).AS("result.in"),
|
||||
AllTypes.SmallIntPtr.IN(AllTypes.SELECT(AllTypes.Integer)).AS("result.in_select"),
|
||||
AllTypes.SmallIntPtr.NOT_IN(Int(11), Int(22), NULL).AS("result.not_in"),
|
||||
AllTypes.SmallIntPtr.NOT_IN(AllTypes.SELECT(AllTypes.Integer)).AS("result.not_in_select"),
|
||||
).LIMIT(2)
|
||||
|
||||
//fmt.Println(query.Sql())
|
||||
|
||||
testutils.AssertStatementSql(t, query, `
|
||||
SELECT all_types.integer IS NULL AS "result.is_null",
|
||||
all_types.date_ptr IS NOT NULL AS "result.is_not_null",
|
||||
(all_types.small_int_ptr IN (?, ?)) AS "result.in",
|
||||
(all_types.small_int_ptr IN ((
|
||||
SELECT all_types.integer AS "all_types.integer"
|
||||
FROM test_sample.all_types
|
||||
))) AS "result.in_select",
|
||||
(all_types.small_int_ptr NOT IN (?, ?, NULL)) AS "result.not_in",
|
||||
(all_types.small_int_ptr NOT IN ((
|
||||
SELECT all_types.integer AS "all_types.integer"
|
||||
FROM test_sample.all_types
|
||||
))) AS "result.not_in_select"
|
||||
FROM test_sample.all_types
|
||||
LIMIT ?;
|
||||
`, int64(11), int64(22), int64(11), int64(22), int64(2))
|
||||
|
||||
var dest []struct {
|
||||
common.ExpressionTestResult `alias:"result.*"`
|
||||
}
|
||||
|
||||
err := query.Query(db, &dest)
|
||||
|
||||
assert.NilError(t, err)
|
||||
|
||||
//testutils.JsonPrint(dest)
|
||||
|
||||
testutils.AssertJSON(t, dest, `
|
||||
[
|
||||
{
|
||||
"IsNull": false,
|
||||
"IsNotNull": true,
|
||||
"In": false,
|
||||
"InSelect": false,
|
||||
"NotIn": null,
|
||||
"NotInSelect": true
|
||||
},
|
||||
{
|
||||
"IsNull": false,
|
||||
"IsNotNull": false,
|
||||
"In": null,
|
||||
"InSelect": null,
|
||||
"NotIn": null,
|
||||
"NotInSelect": null
|
||||
}
|
||||
]
|
||||
`)
|
||||
}
|
||||
|
||||
func TestBoolOperators(t *testing.T) {
|
||||
query := AllTypes.SELECT(
|
||||
AllTypes.Boolean.EQ(AllTypes.BooleanPtr).AS("EQ1"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue