Repository navigation
sql-storage-adapter v0.6.14
·
349 commits
to master
since this release
Fixed
- IndexedDB adapter: the auto-save tick no longer saves while a transaction is open. sql.js's
export()closes and reopens the connection, so a tick that fired while atransaction()callback awaited, or while a transaction begun withBEGINwas open, ended that transaction: its later statements ran outside it, and itsCOMMITorROLLBACKfailed. The tick skips while a transaction is open and saves once it has committed.exportDatabase()throws while a transaction is open instead of ending it. - IndexedDB and Capacitor adapters:
transaction()runs its callbacks one at a time. Both run every transaction on one connection, and a secondtransaction()called while one was open ranBEGINinside it and failed. - IndexedDB and Capacitor adapters: a statement from outside an open transaction waits until the transaction commits or rolls back, as on better-sqlite3 since 0.6.12. It ran inside the transaction: a write was undone when the transaction rolled back, after its caller had been told it succeeded, and a read saw rows the transaction had not committed.
- IndexedDB adapter: a save counts as done when IndexedDB commits it. The adapter marked its writes saved when the put request succeeded, but the IndexedDB transaction can abort after that (a quota error at commit), and the image was then lost while the adapter counted it saved; a write made while a save was in flight was marked saved too and never written. A save settles on the transaction's
completeevent and fails onabort, and it marks saved only the writes its image held, so the next tick saves the rest. A failed save is reported once and tried again on the next tick. - IndexedDB adapter: a transaction whose writes went through
all()orget()(INSERT ... RETURNING) is saved: its commit marks it for saving.importDatabase()saves the imported image before it resolves, and twoclose()calls at once close the adapter once. - Capacitor adapter:
transaction()uses the plugin'sbeginTransaction(),commitTransaction()androllbackTransaction()(plugin 5.0.7 and later, inside the^6.0.0peer range) and sends the callback's statements withtransactionfalse. It ranexecute('BEGIN TRANSACTION;'), which the plugin runs inside a transaction of its own: the transaction failed on iOS and did not hold the callback's statements together on Android.run()reads the plugin's nested answer,{ changes: { changes, lastId } }, and returns the number of changed rows and the inserted row's id; it returned the nested object andnull. - The resolver refuses the adapter kinds it cannot build.
electron-main,electron-renderer,supabaseand any unknown name, frompriorityorSTORAGE_ADAPTER, fail as candidates with an error that names the kind and says how to create it, and the next candidate is tried. They built sql.js.memorybuilds sql.js as before. - On Node,
createDatabase({ url }),createDatabase({ postgres })andconnectDatabase()open PostgreSQL. With nopriorityortype, they chose['better-sqlite3', 'sqljs']and opened a SQLite file atdb_data/app.sqlite3whatever the URL said. A URL, or Postgres options that name a server (a connection string, or a host, database or user), choose['postgres']with no SQLite fallback. Options that name no server ({ connectionString: process.env.DATABASE_URL }withDATABASE_URLunset) keep the local default,DATABASE_URLin the environment does not change whatcreateDatabase()chooses, and a browser and Deno keep sql.js. createDatabase()andresolveStorageAdapter()pass every Postgres option to the pool: its size, SSL, the timeouts and the application name, and host, port, database, user and password without a connection string. Only the connection string reached it. Options that name a server are used instead ofDATABASE_URL.
Changed
- On the IndexedDB and Capacitor adapters, a statement that a transaction's callback issues through the adapter itself, not through the handle it receives, waits for the transaction like any other caller's: a browser or a WebView has no async context to tell the two apart. The callback then waits on itself, and the adapter logs a warning after 10 seconds. Run a callback's statements through its handle.
- A
STORAGE_ADAPTERvalue or apriorityentry outside the kinds above no longer opens sql.js on the resolver's file path. When it was the only candidate, resolution fails with an error that names it;sqljsopens the same file as before. createSyncManager()with aprimary.urlor aremoteURL opens PostgreSQL on Node, as its documentation says; both opened the local SQLite file.- CI starts a PostgreSQL 16 service, and the specs that need a server read its URL from
POSTGRES_TEST_URL.fake-indexeddbis a dev dependency, for the IndexedDB specs.