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

Method RenderMutationCTE

core/internal/dialect/sqlite.go:614–628  ·  view source on GitHub ↗
(ctx Context, m *qcode.Mutate, renderBody func())

Source from the content-addressed store, hash-verified

612}
613
614func (d *SQLiteDialect) RenderMutationCTE(ctx Context, m *qcode.Mutate, renderBody func()) {
615 // SQLite supports CTEs but not writable CTEs data-modifying CTEs (INSERT inside WITH).
616 // So we render the body directly (INSERT ...) so it becomes the main statement.
617 // We inject a dummy CTE to consume the trailing comma from the previous CTE (e.g. input variables).
618 // Result: `WITH input AS (...), "ignored_<table>_<id>" AS (SELECT 1) INSERT ...`
619 var cteName string
620 if m.Multi {
621 cteName = fmt.Sprintf("ignored_%s_%d", m.Ti.Name, m.ID)
622 } else {
623 cteName = "ignored_" + m.Ti.Name
624 }
625 ctx.Quote(cteName)
626 ctx.WriteString(` AS (SELECT 1) `)
627 renderBody()
628}
629
630func (d *SQLiteDialect) RenderInsert(ctx Context, m *qcode.Mutate, values func()) {
631 ctx.WriteString(`INSERT INTO `)

Callers

nothing calls this directly

Calls 2

QuoteMethod · 0.65
WriteStringMethod · 0.65

Tested by

no test coverage detected