diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-03 00:52:15 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-03 00:52:15 +0100 |
commit | c33dd75711a39403bd4dd9940caab6d5e6ad2d77 (patch) | |
tree | 7d7d9c64b5074a8f533302add3b1674c5d424c8d /src/util/query.ts | |
parent | a5137c32650b0b9aa2abbe55e4f4f3f60ed78e07 (diff) | |
download | wallet-core-c33dd75711a39403bd4dd9940caab6d5e6ad2d77.tar.xz |
pending operations (pay/proposals)
Diffstat (limited to 'src/util/query.ts')
-rw-r--r-- | src/util/query.ts | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/util/query.ts b/src/util/query.ts index 6942d471e..b1b19665b 100644 --- a/src/util/query.ts +++ b/src/util/query.ts @@ -25,7 +25,6 @@ */ import { openPromise } from "./promiseUtils"; - /** * Result of an inner join. */ @@ -67,7 +66,7 @@ export interface IndexOptions { } function requestToPromise(req: IDBRequest): Promise<any> { - const stack = Error("Failed request was started here.") + const stack = Error("Failed request was started here."); return new Promise((resolve, reject) => { req.onsuccess = () => { resolve(req.result); @@ -103,7 +102,7 @@ export async function oneShotGet<T>( ): Promise<T | undefined> { const tx = db.transaction([store.name], "readonly"); const req = tx.objectStore(store.name).get(key); - const v = await requestToPromise(req) + const v = await requestToPromise(req); await transactionToPromise(tx); return v; } @@ -335,6 +334,17 @@ class TransactionHandle { return requestToPromise(req); } + getIndexed<S extends IDBValidKey, T>( + index: Index<S, T>, + key: any, + ): Promise<T | undefined> { + const req = this.tx + .objectStore(index.storeName) + .index(index.indexName) + .get(key); + return requestToPromise(req); + } + iter<T>(store: Store<T>, key?: any): ResultStream<T> { const req = this.tx.objectStore(store.name).openCursor(key); return new ResultStream<T>(req); @@ -407,18 +417,20 @@ function runWithTransaction<T>( }; const th = new TransactionHandle(tx); const resP = f(th); - resP.then(result => { - gotFunResult = true; - funResult = result; - }).catch((e) => { - if (e == TransactionAbort) { - console.info("aborting transaction"); - } else { - tx.abort(); - console.error("Transaction failed:", e); - console.error(stack); - } - }); + resP + .then(result => { + gotFunResult = true; + funResult = result; + }) + .catch(e => { + if (e == TransactionAbort) { + console.info("aborting transaction"); + } else { + tx.abort(); + console.error("Transaction failed:", e); + console.error(stack); + } + }); }); } |