Consolidate SQLite parser-shaped helpers#137
Open
mmkal wants to merge 4 commits into
Open
Conversation
commit: |
Route runtime sync, schema diff CREATE classification, and row-return detection through a small tokenizer-backed facade. Add focused tests for comments, strings, quoted identifiers, casts, and statement ordering.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d21ff18. Configure here.
| return { | ||
| name: parseSqliteIdentifierName(raw), | ||
| start: nameToken.start, | ||
| end: nameToken.stop + 1, |
There was a problem hiding this comment.
Qualified names partially rewritten
Medium Severity
When a CREATE statement uses a dotted object name, readIdentifier records a span for only the final segment but leaves the earlier schema. text in place. Runtime sync then splices prefixed or scratch-qualified names into the middle of that qualifier, producing invalid or mis-targeted DDL instead of failing cleanly.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit d21ff18. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Adds a small internal SQLite parser facade backed by the existing vendored
sqlfu-sqlite-parsertokenizer. The facade exposes sqlfu-shaped helpers for tokenization, first-keyword detection, keyword presence, CREATE statement classification, and CREATE identifier spans.The implementation routes parser-shaped call sites through that facade:
on-table rewritessqlReturnsRowsfirst-keyword /returningdetectionBefore / after
Before, these paths each had their own regex/comment-stripping logic, so behavior depended on the local scanner. Schemadiff could see
create virtual tableinside a comment or string literal, and runtime sync name rewriting could classifycreate /* comment */ index ...but still fail when the old rewrite regex tried to find the object name.After, valid SQLite text is classified from tokenizer output, and runtime sync rewrites object names using token spans. Comments, strings, quoted identifiers, and bare identifiers containing
$are handled consistently. The row-return helper keeps a tolerant fallback for PostgreSQL-ish ad hoc SQL such asselect value::json,show timezone, andfetch all from cursor_name, preserving the previous UI behavior while avoiding false positives for normal SQLite strings/comments.Tests
pnpm --filter sqlfu exec vitest run test/sqlfu-sqlite-parser/tokenizer.test.ts test/sqlite-parser.test.ts test/sqlite-text.test.ts test/api-sync.test.ts test/schemadiff/plumbing.test.tspnpm --filter sqlfu typecheckpnpm exec oxfmt --check packages/sqlfu/src/vendor/sqlfu-sqlite-parser/tokenizer.ts packages/sqlfu/src/sqlite-parser.ts packages/sqlfu/src/sqlite-text.ts packages/sqlfu/src/api/sync.ts packages/sqlfu/src/schemadiff/sqlite/index.ts packages/sqlfu/test/sqlfu-sqlite-parser/tokenizer.test.ts packages/sqlfu/test/sqlite-parser.test.ts packages/sqlfu/test/sqlite-text.test.ts packages/sqlfu/test/api-sync.test.ts packages/sqlfu/test/schemadiff/plumbing.test.tsNotes
Named parameter scanning is intentionally left alone in this PR. The existing query-parameter scanner already has focused coverage for comments, strings, and PostgreSQL-style casts; this branch keeps the first parser-facade pass scoped to statement/header and keyword classification.
Package size — packed 244.5 kB (+1.2 kB, +0.5%)
Package size
dist/vendor/*.jsbundlesvendor/sha256.jsvendor/sql-formatter/*.jsvendor/sqlfu-sqlite-parser/*.jsvendor/standard-schema/*.jsvendor/typesql/*.jsMeasured with
npm pack --dry-run --jsononsqlfu(0.0.3-7 on main vs 0.0.3-7 on this PR).Note
Medium Risk
Changes how schema definition SQL is classified and rewritten in runtime sync and schemadiff; behavior is broader but well-covered by new tests, with intentional fallbacks for non-SQLite ad hoc SQL.
Overview
Introduces an internal
sqlite-parserfacade on the vendored tokenizer so runtime sync, schemadiff, andsqlReturnsRowsshare one path for CREATE classification, keyword detection, and identifier spans instead of per-caller regex and comment stripping.Runtime sync and schemadiff now order CREATE statements by tokenized kind (so an index listed before its table still applies correctly), detect virtual tables without false positives in comments/strings, and rewrite CREATE names via span replacement—including comments between keywords and bare identifiers with
$. The tokenizer treats$as part of identifiers (not only bind parameters). Row-return heuristics keep tolerant fallbacks for PostgreSQL-style ad hoc SQL (::json,show,fetch).Reviewed by Cursor Bugbot for commit d21ff18. Bugbot is set up for automated code reviews on this repo. Configure here.