Repository navigation
feat(sqlite): db.pragma() named read/write and stmt.iterate() generator - #50
Merged
Merged
Conversation
…) generator pragmaNamed(name) reads PRAGMA "name", pragmaNamed(name, value) writes a literal value (number/boolean/string with doubled-quote escaping; the pragma parser takes no bound parameters, so values cannot be parameterized). The name is validated against a strict identifier charset before double-quoting, so an injection attempt is SQLITE_MISUSE, never interpolated. iterate(params) binds (schema-validated, same empty-args-keep-bindings rule as all()/get()) and returns a generator yielding one validated row per step. The statement is not reset between rows (reset rewinds), and a finalized statement throws SQLITE_MISUSE eagerly at the iterate() call.
Cover the better-sqlite3 DX surface through koffi: pragmaNamed read rows, numeric/string/boolean writes, injection-name rejection, iterate via for...of, manual next() exhaustion, named-parameter binds, and the eager MISUSE throw on a finalized statement.
…and iterate Same fixtures through scriptc coverage (still 100 percent) and the ELF build: read/write pragmaNamed including quote-in-name rejection, and iterate row streaming with manual next() exhaustion.
Deploying cutilsjs with
|
| Latest commit: |
c9b6bc9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6d9741e4.cutilsjs.pages.dev |
| Branch Preview URL: | https://feat-sqlite-pragma-iterate.cutilsjs.pages.dev |
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
better-sqlite3 DX parity for @cutils/sqlite:
PRAGMA "name"and returns row objects (e.g.db.pragmaNamed("user_version")[0].user_version). Write form takes a number/boolean/string value and returns a RunResult. The name sits in identifier position where binding is impossible, so it is validated against a strict identifier charset first and double-quoted on use: anything else (quotes, semicolons, whitespace) throws SQLITE_MISUSE before reaching prepare. Values cannot be parameterized (the pragma parser takes a literal only —PRAGMA x = ?is a syntax error), so they are emitted as literals: numbers verbatim, booleans as 0/1, strings single-quoted with internal quotes doubled.iterate(). Binds first (schema-validated; empty/omitted args keep current bindings like all()/get()), throws MISUSE eagerly on a finalized statement. Probe-verified thatfunction*class methods lower under both the shipped scriptc 0.4.7 and 0.4.10, so no callback fallback was needed. Implementation note: the statement is deliberately NOT reset between rows — reset rewinds, which replayed the query forever until fixed.pragma(sql)(raw string, returns{ rows }) is unchanged for compatibility.Tests
Also commented on #33 (shim ABI verified at scriptc 0.4.10, no relink needed) and #34 (Symbol.dispose shipped on Database/StmtCore/Transaction) for closure by the maintainer.