MCPcopy
hub / github.com/ent/ent / HasKey

Function HasKey

dialect/sql/sqljson/sqljson.go:22–36  ·  view source on GitHub ↗

HasKey return a predicate for checking that a JSON key exists and not NULL. sqljson.HasKey("column", sql.DotPath("a.b[2].c"))

(column string, opts ...Option)

Source from the content-addressed store, hash-verified

20//
21// sqljson.HasKey("column", sql.DotPath("a.b[2].c"))
22func HasKey(column string, opts ...Option) *sql.Predicate {
23 return sql.P(func(b *sql.Builder) {
24 switch b.Dialect() {
25 case dialect.SQLite:
26 // JSON_TYPE returns NULL in case the path selects an element
27 // that does not exist. See: https://sqlite.org/json1.html#jtype.
28 path := identPath(column, opts...)
29 path.mysqlFunc("JSON_TYPE", b)
30 b.WriteOp(sql.OpNotNull)
31 default:
32 valuePath(b, column, opts...)
33 b.WriteOp(sql.OpNotNull)
34 }
35 })
36}
37
38// ValueIsNull return a predicate for checking that a JSON value
39// (returned by the path) is a null literal (JSON "null").

Callers 2

PredicatesFunction · 0.92
TestWritePathFunction · 0.92

Calls 6

PStruct · 0.92
identPathFunction · 0.85
valuePathFunction · 0.85
mysqlFuncMethod · 0.80
WriteOpMethod · 0.80
DialectMethod · 0.65

Tested by 2

PredicatesFunction · 0.74
TestWritePathFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…