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

Method Append

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

Append implements the driver.Append method.

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

Source from the content-addressed store, hash-verified

16
17// Append implements the driver.Append method.
18func (d *sqlite) Append(u *sql.UpdateBuilder, column string, elems []any, opts ...Option) {
19 setCase(u, column, when{
20 Cond: func(b *sql.Builder) {
21 typ := func(b *sql.Builder) *sql.Builder {
22 return b.WriteString("JSON_TYPE").Wrap(func(b *sql.Builder) {
23 b.Ident(column).Comma()
24 identPath(column, opts...).mysqlPath(b)
25 })
26 }
27 typ(b).WriteOp(sql.OpIsNull)
28 b.WriteString(" OR ")
29 typ(b).WriteOp(sql.OpEQ).WriteString("'null'")
30 },
31 Then: func(b *sql.Builder) {
32 if len(opts) > 0 {
33 b.WriteString("JSON_SET").Wrap(func(b *sql.Builder) {
34 b.Ident(column).Comma()
35 identPath(column, opts...).mysqlPath(b)
36 b.Comma().Argf("JSON(?)", marshalArg(elems))
37 })
38 } else {
39 b.Arg(marshalArg(elems))
40 }
41 },
42 Else: func(b *sql.Builder) {
43 b.WriteString("JSON_INSERT").Wrap(func(b *sql.Builder) {
44 b.Ident(column).Comma()
45 // If no path was provided the top-level value is
46 // a JSON array. i.e. JSON_INSERT(c, '$[#]', ?).
47 path := func(b *sql.Builder) { b.WriteString("'$[#]'") }
48 if len(opts) > 0 {
49 p := identPath(column, opts...)
50 p.Path = append(p.Path, "[#]")
51 path = p.mysqlPath
52 }
53 for i, e := range elems {
54 if i > 0 {
55 b.Comma()
56 }
57 path(b)
58 b.Comma()
59 d.appendArg(b, e)
60 }
61 })
62 },
63 })
64}
65
66func (d *sqlite) appendArg(b *sql.Builder, v any) {
67 switch {

Callers

nothing calls this directly

Calls 13

appendArgMethod · 0.95
setCaseFunction · 0.85
identPathFunction · 0.85
marshalArgFunction · 0.85
WrapMethod · 0.80
WriteStringMethod · 0.80
CommaMethod · 0.80
IdentMethod · 0.80
mysqlPathMethod · 0.80
WriteOpMethod · 0.80
ArgfMethod · 0.80
ArgMethod · 0.80

Tested by

no test coverage detected