diff options
Diffstat (limited to 'src/query.ts')
-rw-r--r-- | src/query.ts | 18 |
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); |