Skip to content

sql-storage-adapter v0.6.14

Choose a tag to compare

@github-actions github-actions released this 15 Oct 12:23
· 349 commits to master since this release
7c7da63

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 a transaction() callback awaited, or while a transaction begun with BEGIN was open, ended that transaction: its later statements ran outside it, and its COMMIT or ROLLBACK failed. 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 second transaction() called while one was open ran BEGIN inside 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 complete event and fails on abort, 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() or get() (INSERT ... RETURNING) is saved: its commit marks it for saving. importDatabase() saves the imported image before it resolves, and two close() calls at once close the adapter once.
  • Capacitor adapter: transaction() uses the plugin's beginTransaction(), commitTransaction() and rollbackTransaction() (plugin 5.0.7 and later, inside the ^6.0.0 peer range) and sends the callback's statements with transaction false. It ran execute('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 and null.
  • The resolver refuses the adapter kinds it cannot build. electron-main, electron-renderer, supabase and any unknown name, from priority or STORAGE_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. memory builds sql.js as before.
  • On Node, createDatabase({ url }), createDatabase({ postgres }) and connectDatabase() open PostgreSQL. With no priority or type, they chose ['better-sqlite3', 'sqljs'] and opened a SQLite file at db_data/app.sqlite3 whatever 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 } with DATABASE_URL unset) keep the local default, DATABASE_URL in the environment does not change what createDatabase() chooses, and a browser and Deno keep sql.js.
  • createDatabase() and resolveStorageAdapter() 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 of DATABASE_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_ADAPTER value or a priority entry 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; sqljs opens the same file as before.
  • createSyncManager() with a primary.url or a remote URL 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-indexeddb is a dev dependency, for the IndexedDB specs.