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

Method RenderLinearValues

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

Source from the content-addressed store, hash-verified

1458}
1459
1460func (d *SQLiteDialect) RenderLinearValues(ctx Context, m *qcode.Mutate, renderRoot func()) {
1461 // Custom implementation for Linear Execution values that handles variable injection
1462 ctx.WriteString(`(SELECT `)
1463
1464 hasPK := false
1465 first := true
1466 for _, col := range m.Cols {
1467 if !first {
1468 ctx.WriteString(`, `)
1469 }
1470 first = false
1471 if m.Ti.IsPKCol(col.Col.Name) {
1472 hasPK = true
1473 }
1474
1475 if col.Set && col.Value != "" {
1476 if strings.HasPrefix(col.Value, "$") {
1477 ctx.WriteString(`(SELECT id FROM _gj_ids WHERE k='`)
1478 ctx.WriteString(col.Value[1:])
1479 ctx.WriteString(`')`)
1480 } else {
1481 if strings.HasPrefix(col.Value, "sql:") {
1482 ctx.WriteString(`(`)
1483 ctx.WriteString(col.Value[4:])
1484 ctx.WriteString(`)`)
1485 } else {
1486 ctx.WriteString("'")
1487 ctx.WriteString(strings.ReplaceAll(col.Value, "'", "''"))
1488 ctx.WriteString("'")
1489 }
1490 }
1491 } else {
1492 if m.Array {
1493 ctx.WriteString(`json_extract(value, '$.`)
1494 } else {
1495 ctx.WriteString(`json_extract(`)
1496 renderRoot()
1497 ctx.WriteString(`, '$.`)
1498 if len(m.Path) > 0 {
1499 ctx.WriteString(strings.Join(m.Path, "."))
1500 ctx.WriteString(`.`)
1501 }
1502 }
1503 ctx.WriteString(col.FieldName)
1504 ctx.WriteString(`')`)
1505 }
1506 ctx.WriteString(` AS `)
1507 ctx.Quote(col.FieldName)
1508 }
1509
1510 if !hasPK {
1511 if !first {
1512 ctx.WriteString(`, `)
1513 }
1514 if m.Array {
1515 renderImplicitPKExtractArray(ctx, m)
1516 } else {
1517 renderImplicitPKExtractSingle(ctx, m, renderRoot)

Callers 2

RenderLinearInsertMethod · 0.95
RenderLinearConnectMethod · 0.95

Calls 5

IsPKColMethod · 0.80
WriteStringMethod · 0.65
QuoteMethod · 0.65

Tested by

no test coverage detected