From 9c85f6277bf85606eb4fbbca47f1a1b5404d2a2e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 23 Feb 2021 20:16:10 +0100 Subject: idb: implement missing methods --- packages/idb-bridge/src/MemoryBackend.ts | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'packages/idb-bridge/src/MemoryBackend.ts') diff --git a/packages/idb-bridge/src/MemoryBackend.ts b/packages/idb-bridge/src/MemoryBackend.ts index 2317fb163..68f60f756 100644 --- a/packages/idb-bridge/src/MemoryBackend.ts +++ b/packages/idb-bridge/src/MemoryBackend.ts @@ -860,6 +860,45 @@ export class MemoryBackend implements Backend { }); } + async clearObjectStore( + btx: DatabaseTransaction, + objectStoreName: string, + ): Promise { + const myConn = this.requireConnectionFromTransaction(btx); + const db = this.databases[myConn.dbName]; + if (!db) { + throw Error("db not found"); + } + if (db.txLevel < TransactionLevel.Write) { + throw Error("only allowed in write transaction"); + } + if ( + db.txRestrictObjectStores && + !db.txRestrictObjectStores.includes(objectStoreName) + ) { + throw Error( + `Not allowed to access store '${objectStoreName}', transaction is over ${JSON.stringify( + db.txRestrictObjectStores, + )}`, + ); + } + + const schema = myConn.modifiedSchema; + const objectStoreMapEntry = myConn.objectStoreMap[objectStoreName]; + + objectStoreMapEntry.store.modifiedData = new BTree([], compareKeys); + + for (const indexName of Object.keys( + schema.objectStores[objectStoreName].indexes, + )) { + const index = myConn.objectStoreMap[objectStoreName].indexMap[indexName]; + if (!index) { + throw Error("index referenced by object store does not exist"); + } + index.modifiedData = new BTree([], compareKeys); + } + } + async deleteRecord( btx: DatabaseTransaction, objectStoreName: string, -- cgit v1.2.3