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:
Ronen Lubin
2022-10-02 15:56:15 +03:00
committed by GitHub
parent 1029a2d3ba
commit 0eaa78f77d
3 changed files with 58 additions and 28 deletions

View File

@@ -109,10 +109,10 @@ type postgres struct{}
func (*postgres) Append(u *sql.UpdateBuilder, column string, elems []any, opts ...Option) {
setCase(u, column, when{
Cond: func(b *sql.Builder) {
ValuePath(b, column, append(opts, Cast("jsonb"))...)
valuePath(b, column, append(opts, Cast("jsonb"))...)
b.WriteOp(sql.OpIsNull)
b.WriteString(" OR ")
ValuePath(b, column, append(opts, Cast("jsonb"))...)
valuePath(b, column, append(opts, Cast("jsonb"))...)
b.WriteOp(sql.OpEQ).WriteString("'null'::jsonb")
},
Then: func(b *sql.Builder) {