summaryrefslogtreecommitdiff
path: root/packages/idb-bridge
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-09-01 10:52:15 +0200
committerFlorian Dold <florian@dold.me>2023-09-01 10:52:15 +0200
commit64e78d03a117fffeb18e18154d9028a2532285a5 (patch)
tree116d1c79b9419f114b6b5f42ce0c8eeb6e88c928 /packages/idb-bridge
parent79973a63dd31c0d84b677a2a1511b1dffc6218b8 (diff)
downloadwallet-core-64e78d03a117fffeb18e18154d9028a2532285a5.tar.gz
wallet-core-64e78d03a117fffeb18e18154d9028a2532285a5.tar.bz2
wallet-core-64e78d03a117fffeb18e18154d9028a2532285a5.zip
wallet-core: implement and test stored backups
Diffstat (limited to 'packages/idb-bridge')
-rw-r--r--packages/idb-bridge/src/SqliteBackend.ts27
-rw-r--r--packages/idb-bridge/src/bridge-idb.ts7
2 files changed, 31 insertions, 3 deletions
diff --git a/packages/idb-bridge/src/SqliteBackend.ts b/packages/idb-bridge/src/SqliteBackend.ts
index c40281861..a25ec0045 100644
--- a/packages/idb-bridge/src/SqliteBackend.ts
+++ b/packages/idb-bridge/src/SqliteBackend.ts
@@ -1882,7 +1882,7 @@ export class SqliteBackend implements Backend {
}
}
- clearObjectStore(
+ async clearObjectStore(
btx: DatabaseTransaction,
objectStoreName: string,
): Promise<void> {
@@ -1906,7 +1906,21 @@ export class SqliteBackend implements Backend {
);
}
- throw new Error("Method not implemented.");
+ this._prep(sqlClearObjectStore).run({
+ object_store_id: scopeInfo.objectStoreId,
+ });
+
+ for (const index of scopeInfo.indexMap.values()) {
+ let stmt: Sqlite3Statement;
+ if (index.unique) {
+ stmt = this._prep(sqlClearUniqueIndexData);
+ } else {
+ stmt = this._prep(sqlClearIndexData);
+ }
+ stmt.run({
+ index_id: index.indexId,
+ });
+ }
}
}
@@ -1963,6 +1977,15 @@ CREATE TABLE IF NOT EXISTS unique_index_data
);
`;
+const sqlClearObjectStore = `
+DELETE FROM object_data WHERE object_store_id=$object_store_id`;
+
+const sqlClearIndexData = `
+DELETE FROM index_data WHERE index_id=$index_id`;
+
+const sqlClearUniqueIndexData = `
+DELETE FROM unique_index_data WHERE index_id=$index_id`;
+
const sqlListDatabases = `
SELECT name, version FROM databases;
`;
diff --git a/packages/idb-bridge/src/bridge-idb.ts b/packages/idb-bridge/src/bridge-idb.ts
index 8cecba534..f3749c77c 100644
--- a/packages/idb-bridge/src/bridge-idb.ts
+++ b/packages/idb-bridge/src/bridge-idb.ts
@@ -735,7 +735,9 @@ export class BridgeIDBDatabase extends FakeEventTarget implements IDBDatabase {
}
if (this._closePending) {
- throw new InvalidStateError();
+ throw new InvalidStateError(
+ `tried to start transaction on ${this._name}, but a close is pending`,
+ );
}
if (!Array.isArray(storeNames)) {
@@ -930,6 +932,9 @@ export class BridgeIDBFactory {
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-running-a-versionchange-transaction
for (const otherConn of this.connections) {
+ if (otherConn._name != db._name) {
+ continue;
+ }
if (otherConn._closePending) {
continue;
}