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

Method RenderUpdate

core/internal/dialect/sqlite.go:639–682  ·  view source on GitHub ↗
(ctx Context, m *qcode.Mutate, set func(), from func(), where func())

Source from the content-addressed store, hash-verified

637}
638
639func (d *SQLiteDialect) RenderUpdate(ctx Context, m *qcode.Mutate, set func(), from func(), where func()) {
640 // Pre-select IDs into _gj_ids for later use by the SELECT query
641 vName := getVarName(m)
642 ctx.WriteString(`INSERT INTO _gj_ids (k, id) SELECT '`)
643 ctx.WriteString(vName)
644 ctx.WriteString(`', `)
645 renderPKIDExpr(ctx, m)
646 ctx.WriteString(` FROM `)
647 ctx.ColWithTable(m.Ti.Schema, m.Ti.Name)
648 ctx.WriteString(` AS `)
649 ctx.Quote(m.Ti.Name)
650 if from != nil {
651 ctx.WriteString(`, `) // Comma for implicit join in SELECT
652 from()
653 }
654 ctx.WriteString(` WHERE `)
655
656 // Add implicit join condition for JSON updates (only for Arrays where ID is in Input)
657 if m.IsJSON && m.Array {
658 renderPKJSONJoin(ctx, m)
659 ctx.WriteString(` AND `)
660 }
661
662 where()
663 ctx.WriteString(`; `)
664
665 ctx.WriteString(`UPDATE `)
666 ctx.ColWithTable(m.Ti.Schema, m.Ti.Name)
667 ctx.WriteString(` SET `)
668 set()
669 if from != nil {
670 ctx.WriteString(` FROM `) // SQLite UPDATE FROM syntax
671 from()
672 }
673 ctx.WriteString(` WHERE `)
674
675 // Add implicit join condition for JSON updates (only for Arrays where ID is in Input)
676 if m.IsJSON && m.Array {
677 renderPKJSONJoin(ctx, m)
678 ctx.WriteString(` AND `)
679 }
680
681 where()
682}
683
684func (d *SQLiteDialect) RenderDelete(ctx Context, m *qcode.Mutate, where func()) {
685 ctx.WriteString(`DELETE FROM `)

Callers 1

RenderLinearUpdateMethod · 0.95

Calls 6

getVarNameFunction · 0.85
renderPKIDExprFunction · 0.85
renderPKJSONJoinFunction · 0.85
WriteStringMethod · 0.65
ColWithTableMethod · 0.65
QuoteMethod · 0.65

Tested by

no test coverage detected