mirror of
https://github.com/ent/ent.git
synced 2026-04-28 21:50:56 +03:00
dialect/sql/sqljson: add option to evaluate json path inside a predicate (#2982)
* dialect/sql/sqljson: add option to evaluate json path inside a predicate * add postgres test case
This commit is contained in:
@@ -44,6 +44,19 @@ func TestWritePath(t *testing.T) {
|
||||
wantQuery: "SELECT * FROM `users` WHERE JSON_EXTRACT(`a`, '$.b.\"c[1]\".d[1][2].e') = ?",
|
||||
wantArgs: []any{"a"},
|
||||
},
|
||||
{
|
||||
input: sql.Select("*").
|
||||
From(sql.Table("test")).
|
||||
Where(sqljson.ValueEQ("j", sqljson.ValuePath("j", sqljson.DotPath("a.*.b")), sqljson.DotPath("a.*.c"))),
|
||||
wantQuery: "SELECT * FROM `test` WHERE JSON_EXTRACT(`j`, '$.a.*.c') = JSON_EXTRACT(`j`, '$.a.*.b')",
|
||||
},
|
||||
{
|
||||
input: sql.Dialect(dialect.Postgres).
|
||||
Select("*").
|
||||
From(sql.Table("test")).
|
||||
Where(sqljson.ValueEQ("j", sqljson.ValuePath("j", sqljson.DotPath("a.*.b")), sqljson.DotPath("a.*.c"))),
|
||||
wantQuery: `SELECT * FROM "test" WHERE "j"->'a'->'*'->>'c' = "j"->'a'->'*'->'b'`,
|
||||
},
|
||||
{
|
||||
input: sql.Select("*").
|
||||
From(sql.Table("test")).
|
||||
|
||||
Reference in New Issue
Block a user