MCPcopy
hub / github.com/dosco/graphjin / RenderMutateToRecordSet

Method RenderMutateToRecordSet

core/internal/dialect/sqlite.go:1198–1279  ·  view source on GitHub ↗
(ctx Context, m *qcode.Mutate, n int, renderRoot func())

Source from the content-addressed store, hash-verified

1196return m.Ti.Name + "_" + fmt.Sprintf("%d", m.ID)
1197}
1198func (d *SQLiteDialect) RenderMutateToRecordSet(ctx Context, m *qcode.Mutate, n int, renderRoot func()) {
1199 if n != 0 {
1200 ctx.WriteString(`, `)
1201 }
1202
1203 if m.Array {
1204 // Bulk inserts are wrapped by mutate.go in a SELECT ... FROM (...) AS t
1205 // So we MUST return a valid subquery with alias 't'.
1206 ctx.WriteString(`(SELECT `)
1207
1208 hasPK := false
1209 first := true
1210 for _, col := range m.Cols {
1211 if !first {
1212 ctx.WriteString(`, `)
1213 }
1214 first = false
1215 if m.Ti.IsPKCol(col.Col.Name) {
1216 hasPK = true
1217 }
1218 ctx.WriteString(`json_extract(value, '$.`)
1219 ctx.WriteString(col.FieldName)
1220 ctx.WriteString(`') AS `)
1221 ctx.Quote(col.FieldName)
1222 }
1223 if !hasPK {
1224 if !first {
1225 ctx.WriteString(`, `)
1226 }
1227 renderImplicitPKExtractArray(ctx, m)
1228 }
1229 ctx.WriteString(` FROM `)
1230 if !d.SupportsLinearExecution() {
1231 ctx.WriteString(`_sg_input AS i, `)
1232 }
1233 ctx.WriteString(`json_each(`)
1234 renderRoot()
1235 if len(m.Path) > 0 {
1236 ctx.WriteString(`, '$.`)
1237 ctx.WriteString(strings.Join(m.Path, "."))
1238 ctx.WriteString(`'`)
1239 }
1240 ctx.WriteString(`)) AS t`)
1241 } else {
1242 // Single object case - always output (SELECT ...) AS t for valid FROM clause
1243 ctx.WriteString(`(SELECT `)
1244
1245 hasPK := false
1246 first := true
1247 for _, col := range m.Cols {
1248 if !first {
1249 ctx.WriteString(`, `)
1250 }
1251 first = false
1252 if m.Ti.IsPKCol(col.Col.Name) {
1253 hasPK = true
1254 }
1255 ctx.WriteString(`json_extract(`)

Callers 1

RenderLinearUpdateMethod · 0.95

Calls 6

IsPKColMethod · 0.80
WriteStringMethod · 0.65
QuoteMethod · 0.65

Tested by

no test coverage detected