dialect/sql/sqljson: add {neq,gt,gte} to predicates (#756)

This commit is contained in:
Ariel Mashraki
2020-09-13 15:25:02 +03:00
committed by GitHub
parent 98bc30d618
commit 690e9cd402
2 changed files with 51 additions and 1 deletions

View File

@@ -92,6 +92,20 @@ func TestWritePath(t *testing.T) {
wantQuery: `SELECT * FROM "users" WHERE CAST("a"->'b'->'c'->1->'d' AS int) = $1`,
wantArgs: []interface{}{1},
},
{
input: sql.Dialect(dialect.Postgres).
Select("*").
From(sql.Table("users")).
Where(
sql.Or(
sqljson.ValueNEQ("a", 1, sqljson.Path("b")),
sqljson.ValueGT("a", 1, sqljson.Path("c")),
sqljson.ValueGTE("a", 1, sqljson.Path("d")),
),
),
wantQuery: `SELECT * FROM "users" WHERE "a"->'b' <> $1 OR "a"->'c' > $2 OR "a"->'d' >= $3`,
wantArgs: []interface{}{1, 1, 1},
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {