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

Method RenderValPrefix

core/internal/dialect/sqlite.go:280–332  ·  view source on GitHub ↗
(ctx Context, ex *qcode.Exp)

Source from the content-addressed store, hash-verified

278}
279
280func (d *SQLiteDialect) RenderValPrefix(ctx Context, ex *qcode.Exp) bool {
281 if ex.Op == qcode.OpHasKey {
282 ctx.WriteString(`json_extract(`)
283 ctx.ColWithTable(ex.Left.Col.Table, ex.Left.Col.Name)
284 ctx.WriteString(`, '$."' || `)
285 if ex.Right.ValType == qcode.ValVar {
286 ctx.AddParam(Param{Name: ex.Right.Val, Type: "text"})
287 } else {
288 ctx.WriteString(fmt.Sprintf("'%s'", ex.Right.Val))
289 }
290 ctx.WriteString(` || '"') IS NOT NULL`)
291 return true
292 }
293
294 if ex.Op == qcode.OpHasKeyAny || ex.Op == qcode.OpHasKeyAll {
295 op := " OR "
296 if ex.Op == qcode.OpHasKeyAll {
297 op = " AND "
298 }
299 ctx.WriteString(`(`)
300 if ex.Right.ValType == qcode.ValVar {
301 // Variable case: use json_each on the variable
302 // EXISTS (SELECT 1 FROM json_each($var) WHERE json_extract(col, '$."' || value || '"') IS NOT NULL)
303 if ex.Op == qcode.OpHasKeyAll {
304 ctx.WriteString(`NOT EXISTS (SELECT 1 FROM json_each(`)
305 } else {
306 ctx.WriteString(`EXISTS (SELECT 1 FROM json_each(`)
307 }
308 ctx.AddParam(Param{Name: ex.Right.Val, Type: "json"})
309 ctx.WriteString(`) WHERE json_extract(`)
310 ctx.ColWithTable(ex.Left.Col.Table, ex.Left.Col.Name)
311 ctx.WriteString(`, '$."' || value || '"') IS `)
312 if ex.Op == qcode.OpHasKeyAll {
313 ctx.WriteString(`NULL)`)
314 } else {
315 ctx.WriteString(`NOT NULL)`)
316 }
317 } else {
318 // Literal list case
319 for i, val := range ex.Right.ListVal {
320 if i != 0 {
321 ctx.WriteString(op)
322 }
323 ctx.WriteString(`json_extract(`)
324 ctx.ColWithTable(ex.Left.Col.Table, ex.Left.Col.Name)
325 ctx.WriteString(`, '$."` + val + `"') IS NOT NULL`)
326 }
327 }
328 ctx.WriteString(`)`)
329 return true
330 }
331 return false
332}
333
334func (d *SQLiteDialect) RenderTsQuery(ctx Context, ti sdata.DBTable, ex *qcode.Exp) {
335 // SQLite FTS5: For content-backed FTS, we need to query the FTS virtual table

Callers

nothing calls this directly

Calls 3

WriteStringMethod · 0.65
ColWithTableMethod · 0.65
AddParamMethod · 0.65

Tested by

no test coverage detected