Append implements the driver.Append method.
(u *sql.UpdateBuilder, column string, elems []any, opts ...Option)
| 16 | |
| 17 | // Append implements the driver.Append method. |
| 18 | func (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 | |
| 66 | func (d *sqlite) appendArg(b *sql.Builder, v any) { |
| 67 | switch { |
nothing calls this directly
no test coverage detected