MCPcopy
hub / github.com/ent/ent / ValueIsNull

Function ValueIsNull

dialect/sql/sqljson/sqljson.go:45–64  ·  view source on GitHub ↗

ValueIsNull return a predicate for checking that a JSON value (returned by the path) is a null literal (JSON "null"). In order to check if the column is NULL (database NULL), or if the JSON key exists, use sql.IsNull or sqljson.HasKey. sqljson.ValueIsNull("a", sqljson.Path("b"))

(column string, opts ...Option)

Source from the content-addressed store, hash-verified

43//
44// sqljson.ValueIsNull("a", sqljson.Path("b"))
45func ValueIsNull(column string, opts ...Option) *sql.Predicate {
46 return sql.P(func(b *sql.Builder) {
47 switch b.Dialect() {
48 case dialect.MySQL:
49 path := identPath(column, opts...)
50 b.WriteString("JSON_CONTAINS").Wrap(func(b *sql.Builder) {
51 b.Ident(column).Comma()
52 b.WriteString("'null'").Comma()
53 path.mysqlPath(b)
54 })
55 case dialect.Postgres:
56 valuePath(b, column, append(opts, Cast("jsonb"))...)
57 b.WriteOp(sql.OpEQ).WriteString("'null'::jsonb")
58 case dialect.SQLite:
59 path := identPath(column, opts...)
60 path.mysqlFunc("JSON_TYPE", b)
61 b.WriteOp(sql.OpEQ).WriteString("'null'")
62 }
63 })
64}
65
66// ValueIsNotNull return a predicate for checking that a JSON value
67// (returned by the path) is not null literal (JSON "null").

Callers 4

PredicatesFunction · 0.92
BackfillUserTagsFunction · 0.92
TestWritePathFunction · 0.92
TestWriteDriverFunction · 0.92

Calls 12

PStruct · 0.92
identPathFunction · 0.85
valuePathFunction · 0.85
CastFunction · 0.85
WrapMethod · 0.80
WriteStringMethod · 0.80
CommaMethod · 0.80
IdentMethod · 0.80
mysqlPathMethod · 0.80
WriteOpMethod · 0.80
mysqlFuncMethod · 0.80
DialectMethod · 0.65

Tested by 3

PredicatesFunction · 0.74
TestWritePathFunction · 0.74
TestWriteDriverFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…