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

Method Append

dialect/sql/sqljson/dialect.go:141–178  ·  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

139
140// Append implements the driver.Append method.
141func (*postgres) Append(u *sql.UpdateBuilder, column string, elems []any, opts ...Option) {
142 setCase(u, column, when{
143 Cond: func(b *sql.Builder) {
144 valuePath(b, column, append(opts, Cast("jsonb"))...)
145 b.WriteOp(sql.OpIsNull)
146 b.WriteString(" OR ")
147 valuePath(b, column, append(opts, Cast("jsonb"))...)
148 b.WriteOp(sql.OpEQ).WriteString("'null'::jsonb")
149 },
150 Then: func(b *sql.Builder) {
151 if len(opts) > 0 {
152 b.WriteString("jsonb_set").Wrap(func(b *sql.Builder) {
153 b.Ident(column).Comma()
154 identPath(column, opts...).pgArrayPath(b)
155 b.Comma().Arg(marshalArg(elems))
156 b.Comma().WriteString("true")
157 })
158 } else {
159 b.Arg(marshalArg(elems))
160 }
161 },
162 Else: func(b *sql.Builder) {
163 if len(opts) > 0 {
164 b.WriteString("jsonb_set").Wrap(func(b *sql.Builder) {
165 b.Ident(column).Comma()
166 identPath(column, opts...).pgArrayPath(b)
167 b.Comma()
168 path := identPath(column, opts...)
169 path.value(b)
170 b.WriteString(" || ").Arg(marshalArg(elems))
171 b.Comma().WriteString("true")
172 })
173 } else {
174 b.Ident(column).WriteString(" || ").Arg(marshalArg(elems))
175 }
176 },
177 })
178}
179
180// driver groups all dialect-specific methods.
181type driver interface {

Callers

nothing calls this directly

Calls 13

setCaseFunction · 0.85
valuePathFunction · 0.85
CastFunction · 0.85
identPathFunction · 0.85
marshalArgFunction · 0.85
WriteOpMethod · 0.80
WriteStringMethod · 0.80
WrapMethod · 0.80
CommaMethod · 0.80
IdentMethod · 0.80
pgArrayPathMethod · 0.80
ArgMethod · 0.80

Tested by

no test coverage detected