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

Method RenderLinearUpdate

core/internal/dialect/sqlite.go:874–931  ·  view source on GitHub ↗
(ctx Context, m *qcode.Mutate, qc *qcode.QCode, varName string, renderColVal func(qcode.MColumn), renderWhere func())

Source from the content-addressed store, hash-verified

872}
873
874func (d *SQLiteDialect) RenderLinearUpdate(ctx Context, m *qcode.Mutate, qc *qcode.QCode, varName string, renderColVal func(qcode.MColumn), renderWhere func()) {
875 var fromFunc func()
876 if m.IsJSON {
877 fromFunc = func() {
878 d.RenderMutateToRecordSet(ctx, m, 0, func() {
879 ctx.AddParam(Param{Name: qc.ActionVar, Type: "json"})
880 })
881 }
882 }
883
884
885 d.RenderUpdate(ctx, m, func() {
886 // Set
887 i := 0
888 for _, col := range m.Cols {
889 if i != 0 {
890 ctx.WriteString(", ")
891 }
892 // SQLite restriction on qualified column names in SET
893 ctx.Quote(col.Col.Name)
894 ctx.WriteString(" = ")
895 renderColVal(col)
896 i++
897 }
898 for range m.RCols {
899 // For SQLite updates, we don't want to update the relationship columns
900 // in the SET clause, as we handle the join in the WHERE clause?
901 // mutate.go logic: line 329: if c.dialect.Name() == "sqlite" { continue }
902 // So we skip them here.
903 continue
904 }
905
906 if i == 0 {
907 for j, pkCol := range m.Ti.PrimaryCols {
908 if j > 0 {
909 ctx.WriteString(`, `)
910 }
911 ctx.Quote(pkCol.Name)
912 ctx.WriteString(" = ")
913 ctx.Quote(pkCol.Name)
914 }
915 }
916 }, fromFunc, func() {
917 // Where
918 // Logic from mutate.go lines 402+
919 // c.renderExp(path...)
920
921 // Also handle join conditions.
922 // mutate.go: if m.ParentID != -1 ... AND childCol = (SELECT parentCol FROM ... WHERE ...)
923
924 renderWhere() // Renders m.Where.Exp
925 })
926
927 d.RenderReturning(ctx, m)
928 ctx.WriteString(" -- @gj_ids=")
929 ctx.WriteString(varName)
930 ctx.WriteString("\n; ")
931}

Callers

nothing calls this directly

Calls 6

RenderUpdateMethod · 0.95
RenderReturningMethod · 0.95
AddParamMethod · 0.65
WriteStringMethod · 0.65
QuoteMethod · 0.65

Tested by

no test coverage detected