dialect/sql/sqljson: add length predicate (#763)

This commit is contained in:
Ariel Mashraki
2020-09-15 11:53:54 +03:00
committed by GitHub
parent 54774960b2
commit 3578d73a8f
3 changed files with 126 additions and 42 deletions

View File

@@ -108,6 +108,30 @@ func TestWritePath(t *testing.T) {
wantQuery: `SELECT * FROM "users" WHERE ("a"->>'b')::int <> $1 OR ("a"->>'c')::int > $2 OR ("a"->>'d')::float >= $3 OR ("a"->>'e')::int < $4 OR ("a"->>'f')::int <= $5`,
wantArgs: []interface{}{1, 1, 1.1, 1, 1},
},
{
input: sql.Dialect(dialect.Postgres).
Select("*").
From(sql.Table("users")).
Where(sqljson.LenEQ("a", 1)),
wantQuery: `SELECT * FROM "users" WHERE JSONB_ARRAY_LENGTH("a") = $1`,
wantArgs: []interface{}{1},
},
{
input: sql.Dialect(dialect.MySQL).
Select("*").
From(sql.Table("users")).
Where(sqljson.LenEQ("a", 1)),
wantQuery: "SELECT * FROM `users` WHERE JSON_LENGTH(`a`, \"$\") = ?",
wantArgs: []interface{}{1},
},
{
input: sql.Dialect(dialect.SQLite).
Select("*").
From(sql.Table("users")).
Where(sqljson.LenEQ("a", 1)),
wantQuery: "SELECT * FROM `users` WHERE JSON_ARRAY_LENGTH(`a`, \"$\") = ?",
wantArgs: []interface{}{1},
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {