MCPcopy Index your code
hub / github.com/ent/ent / ValueContains

Function ValueContains

dialect/sql/sqljson/sqljson.go:175–201  ·  view source on GitHub ↗

ValueContains return a predicate for checking that a JSON value (returned by the path) contains the given argument. sqljson.ValueContains("a", 1, sqljson.Path("b"))

(column string, arg any, opts ...Option)

Source from the content-addressed store, hash-verified

173//
174// sqljson.ValueContains("a", 1, sqljson.Path("b"))
175func ValueContains(column string, arg any, opts ...Option) *sql.Predicate {
176 return sql.P(func(b *sql.Builder) {
177 path := identPath(column, opts...)
178 switch b.Dialect() {
179 case dialect.MySQL:
180 b.WriteString("JSON_CONTAINS").Wrap(func(b *sql.Builder) {
181 b.Ident(column).Comma()
182 b.Arg(marshalArg(arg)).Comma()
183 path.mysqlPath(b)
184 })
185 b.WriteOp(sql.OpEQ).Arg(1)
186 case dialect.SQLite:
187 b.WriteString("EXISTS").Wrap(func(b *sql.Builder) {
188 b.WriteString("SELECT * FROM JSON_EACH").Wrap(func(b *sql.Builder) {
189 b.Ident(column).Comma()
190 path.mysqlPath(b)
191 })
192 b.WriteString(" WHERE ").Ident("value").WriteOp(sql.OpEQ).Arg(arg)
193 })
194 case dialect.Postgres:
195 opts = normalizePG(b, arg, opts)
196 path.Cast = "jsonb"
197 path.value(b)
198 b.WriteString(" @> ").Arg(marshalArg(arg))
199 }
200 })
201}
202
203// StringHasPrefix return a predicate for checking that a JSON string value
204// (returned by the path) has the given substring as prefix

Callers 3

PredicatesFunction · 0.92
BackfillUserTagsFunction · 0.92
TestWritePathFunction · 0.92

Calls 13

PStruct · 0.92
identPathFunction · 0.85
marshalArgFunction · 0.85
normalizePGFunction · 0.85
WrapMethod · 0.80
WriteStringMethod · 0.80
CommaMethod · 0.80
IdentMethod · 0.80
ArgMethod · 0.80
mysqlPathMethod · 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…