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

Method RenderCursorCTE

core/internal/dialect/sqlite.go:102–132  ·  view source on GitHub ↗
(ctx Context, sel *qcode.Select)

Source from the content-addressed store, hash-verified

100
101
102func (d *SQLiteDialect) RenderCursorCTE(ctx Context, sel *qcode.Select) {
103 if !sel.Paging.Cursor {
104 return
105 }
106 // SQLite: Parse comma-separated cursor as JSON array
107 // Convert "val1,val2,val3" to '["val1","val2","val3"]' then use json_each
108 ctx.WriteString(`WITH __cur AS (SELECT `)
109 cursorVar := sel.Paging.CursorVar
110 if cursorVar == "" {
111 cursorVar = "cursor"
112 }
113 for i, ob := range sel.OrderBy {
114 if i != 0 {
115 ctx.WriteString(`, `)
116 }
117 // Use json_extract with array index (0-based in SQLite JSON)
118 ctx.WriteString(`CAST(json_extract('["' || replace(NULLIF(`)
119 ctx.AddParam(Param{Name: cursorVar, Type: "text"})
120 ctx.WriteString(`, ''), ',', '","') || '"]', '$[`)
121 ctx.WriteString(fmt.Sprintf("%d", i+1))
122 ctx.WriteString(`]') AS `)
123 ctx.WriteString(d.sqliteType(ob.Col.Type))
124 ctx.WriteString(`) AS `)
125 if ob.KeyVar != "" && ob.Key != "" {
126 ctx.Quote(ob.Col.Name + "_" + ob.Key)
127 } else {
128 ctx.Quote(ob.Col.Name)
129 }
130 }
131 ctx.WriteString(`)`)
132}
133
134// sqliteType converts GraphJin types to SQLite types
135func (d *SQLiteDialect) sqliteType(t string) string {

Callers

nothing calls this directly

Calls 4

sqliteTypeMethod · 0.95
WriteStringMethod · 0.65
AddParamMethod · 0.65
QuoteMethod · 0.65

Tested by

no test coverage detected