IndexedDB noob here...
const queueStore = db.createObjectStore("queue", { keyPath: "id", autoIncrement: true });
queueStore.createIndex("HasBeenSent", ["sent"], { unique: false });
I am queuing data, awaiting an upload to a server at a later time, so for now the "sent" value is zero for each record; I'll update the record to reflect "sent" equals 1 later.
When I try to get all the records where the value of "sent" is zero, I get an empty result, using
request = db.transaction('queue').objectStore('queue').index('HasBeenSent').getAll(0);
If I remove the zero and just have empty brackets, I get all the rows in the store, but if I include any value in the brackets (0, 1, -1, etc) every time I get empty results, even if I definitely have stored records with those values.
(Have I messed something up in the configuration?)
How do I query the store to return all rows where "sent" equals zero??
I read through various sources that getAll() is ok on small datasets, but it can be slow and hungry on large datasets, so I decided to use cursors which should perform better on both large and small datasets. But, I ran into the same issue with empty results.
What didn't work:
const request = db.transaction('queue').objectStore('queue').index('sent').openCursor(0);
nor
const request = db.transaction('queue').objectStore('queue').index('sent').openCursor(IDBKeyRange.only(0));
What DID work
const keyrange = IDBKeyRange.only(0);
const request = db.transaction('queue').objectStore('queue').index('sent').openCursor(keyrange);
I imagine (but never tested) that using getAll(), you'd need to do something similar by defining the keyrange first, then including that in the getAll() request, like
const keyrange = IDBKeyRange.only(0);
const request = db.transaction('queue').objectStore('queue').index('sent').getAll(keyrange);