commit 64d370a6b24eeef111c6d72acf8a5dcb2206192e
parent 5bfdd5f8373db85dab5d231277f6df9f9ec24b84
Author: Florian Dold <dold@taler.net>
Date: Thu, 6 Aug 2026 20:32:05 +0200
idb-bridge: allow building the sqlite backend over an open connection
wallet-core migrates the database it stores here to a different schema in the
same file, and a second connection to that file would bring its own
transaction state and its own locks.
Issue: https://bugs.taler.net/n/11718
Diffstat:
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/packages/idb-bridge/src/SqliteBackend.ts b/packages/idb-bridge/src/SqliteBackend.ts
@@ -2531,7 +2531,26 @@ export async function createSqliteBackend(
sqliteImpl: Sqlite3Interface,
options: SqliteBackendOptions,
): Promise<SqliteBackend> {
- const db = await sqliteImpl.open(options.filename);
+ return await createSqliteBackendOverDb(
+ sqliteImpl,
+ await sqliteImpl.open(options.filename),
+ );
+}
+
+/**
+ * Build the backend over a connection the caller already opened.
+ *
+ * For callers that have to use the same connection for something else --
+ * wallet-core migrates the database it stores here to a different schema in
+ * the same file, and doing that over a second connection to the same file
+ * would mean two independent transaction states.
+ *
+ * The caller owns the connection: close() here does not close it.
+ */
+export async function createSqliteBackendOverDb(
+ sqliteImpl: Sqlite3Interface,
+ db: Sqlite3Database,
+): Promise<SqliteBackend> {
await db.exec("PRAGMA foreign_keys = ON;");
await db.exec(schemaSql);
return new SqliteBackend(sqliteImpl, db);