mirror of
https://github.com/ent/ent.git
synced 2026-04-28 13:40:56 +03:00
dialect/sql/sqljson: fix sqlite haskey and add docs
This commit is contained in:
committed by
Ariel Mashraki
parent
3ba2b4e173
commit
0dd7b0d7c3
@@ -21,8 +21,24 @@ import (
|
||||
//
|
||||
func HasKey(column string, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
ValuePath(b, column, opts...)
|
||||
b.WriteOp(sql.OpNotNull)
|
||||
switch b.Dialect() {
|
||||
case dialect.SQLite:
|
||||
b.Nested(func(b *sql.Builder) {
|
||||
b.Join(
|
||||
sql.Or(
|
||||
// The result is NULL for JSON null.
|
||||
sql.P(func(b *sql.Builder) {
|
||||
ValuePath(b, column, opts...)
|
||||
b.WriteOp(sql.OpNotNull)
|
||||
}),
|
||||
ValueIsNull(column, opts...),
|
||||
),
|
||||
)
|
||||
})
|
||||
default:
|
||||
ValuePath(b, column, opts...)
|
||||
b.WriteOp(sql.OpNotNull)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user