From c33dd75711a39403bd4dd9940caab6d5e6ad2d77 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 3 Dec 2019 00:52:15 +0100 Subject: pending operations (pay/proposals) --- src/util/query.ts | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'src/util') 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 { - 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( ): Promise { 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( + index: Index, + key: any, + ): Promise { + const req = this.tx + .objectStore(index.storeName) + .index(index.indexName) + .get(key); + return requestToPromise(req); + } + iter(store: Store, key?: any): ResultStream { const req = this.tx.objectStore(store.name).openCursor(key); return new ResultStream(req); @@ -407,18 +417,20 @@ function runWithTransaction( }; 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); + } + }); }); } -- cgit v1.2.3