aboutsummaryrefslogtreecommitdiff
path: root/src/query.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-27 05:42:46 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-27 05:42:46 +0200
commit63914ab53b18ec29269c2c3fe4e01ac9b36330e5 (patch)
tree62e8e47fa6d85d57eaf419ee8fa88ece62286ad5 /src/query.ts
parentccc6d822424be9b257e63b0d71f2d46f2523fe3e (diff)
make sure that refreshing works after refund
Diffstat (limited to 'src/query.ts')
-rw-r--r--src/query.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/query.ts b/src/query.ts
index ee1ac2603..d7689f2bc 100644
--- a/src/query.ts
+++ b/src/query.ts
@@ -547,9 +547,18 @@ export class QueryRoot {
private finished: boolean = false;
+ private keys: { [keyName: string]: IDBValidKey } = {};
+
constructor(public db: IDBDatabase) {
}
+ /**
+ * Get a named key that was created during the query.
+ */
+ key(keyName: string): IDBValidKey|undefined {
+ return this.keys[keyName];
+ }
+
private checkFinished() {
if (this.finished) {
throw Error("Can't add work to query after it was started");
@@ -627,10 +636,15 @@ export class QueryRoot {
* Overrides if an existing object with the same key exists
* in the store.
*/
- put<T>(store: Store<T>, val: T): QueryRoot {
+ put<T>(store: Store<T>, val: T, keyName?: string): QueryRoot {
this.checkFinished();
const doPut = (tx: IDBTransaction) => {
- tx.objectStore(store.name).put(val);
+ const req = tx.objectStore(store.name).put(val);
+ if (keyName) {
+ req.onsuccess = () => {
+ this.keys[keyName] = req.result;
+ };
+ }
};
this.scheduleFinish();
this.addWork(doPut, store.name, true);