dialect/sql/sqljson: add ValueIsNotNull predicate (#3058)

* dialect/sql: add json ValueIsNotNull predicate

* get rid of false positive dupl linter warning

* add json valueIsNotNull case to integration tests

* fix rejects
This commit is contained in:
Ronen Lubin
2022-11-02 11:18:15 +02:00
committed by GitHub
parent 35d0d4c3db
commit 5d4f02620d
3 changed files with 47 additions and 1 deletions

View File

@@ -256,6 +256,27 @@ func TestWritePath(t *testing.T) {
Where(sqljson.ValueIsNull("c", sqljson.Path("a"))),
wantQuery: "SELECT * FROM `users` WHERE JSON_TYPE(`c`, '$.a') = 'null'",
},
{
input: sql.Dialect(dialect.Postgres).
Select("*").
From(sql.Table("users")).
Where(sqljson.ValueIsNotNull("c", sqljson.Path("a"))),
wantQuery: `SELECT * FROM "users" WHERE ("c"->'a')::jsonb <> 'null'::jsonb`,
},
{
input: sql.Dialect(dialect.MySQL).
Select("*").
From(sql.Table("users")).
Where(sqljson.ValueIsNotNull("c", sqljson.Path("a"))),
wantQuery: "SELECT * FROM `users` WHERE NOT(JSON_CONTAINS(`c`, 'null', '$.a'))",
},
{
input: sql.Dialect(dialect.SQLite).
Select("*").
From(sql.Table("users")).
Where(sqljson.ValueIsNotNull("c", sqljson.Path("a"))),
wantQuery: "SELECT * FROM `users` WHERE JSON_TYPE(`c`, '$.a') <> 'null'",
},
{
input: sql.Dialect(dialect.Postgres).
Select("*").