idb: extend test case

This commit is contained in:
Florian Dold 2019-06-25 13:44:03 +02:00
parent b3fc710d9a
commit df5619236b
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 28 additions and 2 deletions

View File

@ -214,6 +214,23 @@ test("Spec: Example 1 Part 3", async t => {
cursor = request6.result;
t.is(cursor, null);
const request7 = index5.openCursor(null, "prevunique");
await promiseFromRequest(request7);
cursor = request7.result;
t.is(cursor.value.author, "Fred");
t.is(cursor.value.isbn, 234567);
cursor.continue();
await promiseFromRequest(request7);
cursor = request7.result;
t.is(cursor.value.author, "Barney");
cursor.continue();
await promiseFromRequest(request7);
cursor = request7.result;
t.is(cursor, null);
db.close();
t.pass();

View File

@ -640,7 +640,16 @@ export class MemoryBackend implements Backend {
objectStoreProperties.indexes.push(indexName);
schema.indexes[indexName] = indexProperties;
// FIXME: build index from existing object store!
const objectStore = myConn.objectStoreMap[objectStoreName];
if (!objectStore) {
throw Error("object store does not exist");
}
const storeData = objectStore.modifiedData || objectStore.originalData;
storeData.forEach((v, k) => {
this.insertIntoIndex(newIndex, k, v.value, indexProperties);
});
}
async deleteRecord(

View File

@ -53,7 +53,7 @@ export interface IMapSource<K=any, V=any> extends ISetSource<K>
/** Calls callbackFn once for each key-value pair present in the map object.
* The ES6 Map class sends the value to the callback before the key, so
* this interface must do likewise. */
forEach(callbackFn: (v:V, k:K, map:IMapSource<K,V>) => void, thisArg: any): void;
forEach(callbackFn: (v:V, k:K, map:IMapSource<K,V>) => void, thisArg?: any): void;
/** Returns an iterator that provides all key-value pairs from the collection (as arrays of length 2). */
entries(): IterableIterator<[K,V]>;