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)
| 20 | // |
| 21 | // sqljson.HasKey("column", sql.DotPath("a.b[2].c")) |
| 22 | func 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"). |