knex_dart_sqlite 0.4.2
knex_dart_sqlite: ^0.4.2 copied to clipboard
SQLite driver for knex_dart — connect and execute queries against a SQLite database using the knex_dart query builder.
0.4.2 #
Six bugs found by an adversarial review of this driver. All six failed silently — wrong results or a hung stream, never an error — and each is covered by a regression test confirmed to fail before the fix.
-
Web/OPFS: a named database never persisted anything. Opening with
webStorageMode: 'opfs'acceptedCREATE TABLEandINSERTwithout complaint and had lost everything by the next open. The driver passed the caller's filename as both the OPFS directory and the sqlite path, butSimpleOpfsFileSystempersists exactly two paths —/databaseand/database-journal— and itsxOpenfalls through to an in-memory overlay for any other path, so every write went to memory and was dropped on close. The sqlite path is now fixed at/database, chosen from the filesystem actually in use rather than from the requested mode, soautomode is covered whenever it selects OPFS. Databases stay separated by the OPFS directory, which is still keyed by name. (#35) -
WITH ... SELECTqueries returned no rows. The statement kind was guessed from the SQL text —startsWith('SELECT'),startsWith('PRAGMA'),contains('RETURNING')— and a CTE matches none of them, so it took the no-rows branch and returned[]for a query that had rows. Reachable from the typed builder, not just raw SQL:.withQuery(...)was affected. SQL led by a comment (/* ... */ SELECT) was misread the same way. The kind is no longer inferred from the text at all; every statement goes throughselect(), which returns whatever result columns the statement declares and applies DDL/DML side effects exactly as before. -
One client's transaction made another client think it was nested. The "already inside a transaction" marker was a
staticfield, so it was shared by every client instance. A top-leveltrx()on client B, called from inside client A's transaction, saw A's marker, skipped B's own serialization queue and issuedSAVEPOINT/RELEASEwithout ever having runBEGIN— failing withno such savepoint. The marker and the savepoint counter are now per-instance, matching the fix already made inknex_dart_postgres. -
watch()never ended when the database closed. Its subscription had noonDone, so the stream stayed open afterclose():await forover a watch stream never returned and the subscription was never released. Stream completion is now forwarded, and so are errors. -
streamQuery()leaked its statement when the stream was cancelled early, locking the table. The stream wasStream.fromIterableover async*generator; cancelling abandons that iterator without running the generator'sfinally, so the prepared statement was never closed and its cursor kept a read lock. A laterDROP TABLEon that table then failed withdatabase table is locked(SqliteException(6)). It is now anasync*generator, which is terminated on cancel and does runfinally. The web client already usedasync*and was never affected. -
The prepared-statement cache was unbounded. It is keyed by SQL text, so SQL assembled per request — an
INlist whose length varies, a predicate built from user input — produced a new key every time, and neither the map nor the native statements behind it ever stopped growing. Now capped at 128 entries, evicting least-recently-used and closing what it evicts.
Known limitation, unchanged and pre-existing: concurrent nested transactions
on a single client (db.trx((t) => Future.wait([t.trx(...), t.trx(...)])))
still fail with no such savepoint. Only outermost scopes are serialized, and
SQLite savepoints form a stack, so interleaved nested scopes release each
other's. Serializing the nested branch risks deadlocking a nested transaction
that awaits another, so it is left alone here rather than changed under a bug
fix.
0.4.1 #
- Bumped
sqlite3to^3.0.0andsqlite3_webto^0.9.0; replaced deprecated.dispose()calls with.close()in the native and web clients. - Bumped
lintsto^6.1.0andtestto^1.31.0.
0.4.0 #
- Added
watch()reactive query streams for SQLite based onUPDATE_HOOK. - Added web/WASM storage mode selection via
webStorageMode/storageModewithmemory,indexedDb,opfs, andautomodes. - Serialized concurrent top-level transactions across native and web clients.
- Buffered web SQLite update notifications through transaction boundaries to
match native
watch()semantics. - Added coverage for concurrent transactions, reactive query behavior, and native/web storage mode handling.
0.3.0 #
- Added
QueryInterceptorpipeline support: attach OTel, logging, or custom interceptors via theinterceptorsparameter onKnexSQLite.connect(). - Fixed
destroyPool()idempotency — double close no longer throws. - Fixed
StateErroron query after close with a clear message. - Improved exception propagation in transaction rollback using
Error.throwWithStackTraceto preserve original stack traces. - Fixed savepoint ID generation to use a per-instance counter instead of timestamp-based IDs, avoiding collisions under concurrent transactions.
0.2.1 #
- Reduced wrapper overhead by reusing compiled SQL through the interceptor pipeline instead of compiling the same query twice.
- Removed redundant async wrappers in low-level query dispatch while preserving
public
Futuresemantics and error propagation. - Optimized native SQLite row mapping by reading
ResultSetcolumn names and rows directly. - No query result shape, binding behavior, or SQL execution semantics changed.
0.2.0 #
- Added web/WASM SQLite support with conditional web client loading.
- Added async web client initialization and configurable WASM URL support via
connection['wasmUri'], including fallback URI behavior. - Added prepared statement caching in native SQLite client execution path.
- Added stream query support in native SQLite client.
- Updated dependencies for web/WASM compatibility (
sqlite3update,sqlite3_web, anduniversal_io).
0.1.1 #
- Updated dependency to
knex_dart: ^1.1.0. - Uses core
runInTransaction(...)migration transaction path with SQLite-safe behavior.
0.1.0 #
- Initial release.
- SQLite driver for
knex_dartusing thesqlite3package. KnexSQLite.connect()factory supporting file-based and in-memory databases.- Full query execution: select, insert, update, delete.
- Transaction support via
trx(). - Schema execution via
executeSchema().