diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-02 17:35:47 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-02 17:35:47 +0100 |
commit | b5ee6b7b4ee506712f51e1b90e9256c4b0c0c603 (patch) | |
tree | 7d8bb4398ab52b58a5223d37e058eaea6c72f963 /src/util/query.ts | |
parent | e1369ff7e8fc02116b9c4261036f0e42e3423cf4 (diff) |
pending operations WIP
Diffstat (limited to 'src/util/query.ts')
-rw-r--r-- | src/util/query.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/util/query.ts b/src/util/query.ts index 5726bcaa6..6942d471e 100644 --- a/src/util/query.ts +++ b/src/util/query.ts @@ -351,15 +351,32 @@ class TransactionHandle { } } +export function runWithReadTransaction<T>( + db: IDBDatabase, + stores: Store<any>[], + f: (t: TransactionHandle) => Promise<T>, +): Promise<T> { + return runWithTransaction<T>(db, stores, f, "readonly"); +} + export function runWithWriteTransaction<T>( db: IDBDatabase, stores: Store<any>[], f: (t: TransactionHandle) => Promise<T>, ): Promise<T> { + return runWithTransaction<T>(db, stores, f, "readwrite"); +} + +function runWithTransaction<T>( + db: IDBDatabase, + stores: Store<any>[], + f: (t: TransactionHandle) => Promise<T>, + mode: "readonly" | "readwrite", +): Promise<T> { const stack = Error("Failed transaction was started here."); return new Promise((resolve, reject) => { const storeName = stores.map(x => x.name); - const tx = db.transaction(storeName, "readwrite"); + const tx = db.transaction(storeName, mode); let funResult: any = undefined; let gotFunResult: boolean = false; tx.oncomplete = () => { |