Skip to content
Source
Sign inSign up
TanStack/db

fix(sqlite): inline JSON paths for expression indexes #1487

Closedlalitkapoor(GitHub profile, opens in a new tab)wants to merge 5 commits intomain fromrefs/pull/1487/headopened

Showing 4 changed files with 136 additions and 5 deletions (loading 1).

x
0 of 4 viewed, 4 left
6 additions and 0 deletions.changeset/fast-pianos-teach.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/browser-db-sqlite-persistence': patch
+'@tanstack/db-sqlite-persistence-core': patch
+---
+​
+Fix SQLite expression-index matching for persisted ref filters by inlining JSON-path literals in runtime SQL compilation while keeping actual filter values bound.
9 additions and 5 deletionspackages/db-sqlite-persistence-core/src/sqlite-core-adapter.tsModified
View file
@@ -579,18 +579,22 @@
function compileRefExpressionSql(jsonPath: string): CompiledSqlFragment {
const typePath = `${jsonPath}.${PERSISTED_TYPE_TAG}`
const taggedValuePath = `${jsonPath}.${PERSISTED_VALUE_TAG}`
+ // Inline JSON paths so SQLite can match runtime refs to expression-index SQL.
+ const typePathSql = toSqliteLiteral(typePath)
+ const taggedValuePathSql = toSqliteLiteral(taggedValuePath)
+ const jsonPathSql = toSqliteLiteral(jsonPath)
​
return {
supported: true,
- sql: `(CASE json_extract(value, ?)
- WHEN 'bigint' THEN CAST(json_extract(value, ?) AS NUMERIC)
- WHEN 'date' THEN json_extract(value, ?)
+ sql: `(CASE json_extract(value, ${typePathSql})
+ WHEN 'bigint' THEN CAST(json_extract(value, ${taggedValuePathSql}) AS NUMERIC)