MCPcopy
hub / github.com/ent/ent / Append

Function Append

dialect/sql/sqljson/sqljson.go:391–406  ·  view source on GitHub ↗

Append writes to the given SQL builder the SQL command for appending JSON values into the array, optionally defined as a key. Note, the generated SQL will use the Go semantics, the JSON column/key will be set to the given Array in case it is `null` or NULL. For example: Append(u, column, []string{

(u *sql.UpdateBuilder, column string, elems []T, opts ...Option)

Source from the content-addressed store, hash-verified

389// WHEN (("c"->'a')::jsonb IS NULL OR ("c"->'a')::jsonb = 'null'::jsonb)
390// THEN jsonb_set("c", '{a}', $1, true) ELSE jsonb_set("c", '{a}', "c"->'a' || $2, true) END
391func Append[T any](u *sql.UpdateBuilder, column string, elems []T, opts ...Option) {
392 if len(elems) == 0 {
393 u.AddError(fmt.Errorf("sqljson: cannot append an empty array to column %q", column))
394 return
395 }
396 drv, err := newDriver(u.Dialect())
397 if err != nil {
398 u.AddError(err)
399 return
400 }
401 vs := make([]any, len(elems))
402 for i, e := range elems {
403 vs[i] = e
404 }
405 drv.Append(u, column, vs, opts...)
406}
407
408// Option allows for calling database JSON paths with functional options.
409type Option func(*PathOptions)

Callers 14

sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
StringsFunction · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92
sqlSaveMethod · 0.92

Calls 4

newDriverFunction · 0.85
DialectMethod · 0.65
AppendMethod · 0.65
AddErrorMethod · 0.45

Tested by 2

StringsFunction · 0.74
TestAppendFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…