I'm new to indexeddb. Let's say I put several objects to indexed db:
transaction.objectStore("some_store").put(some_object, some_key);
Now I want to get all keys from that object store. Is that possible? If yes, how?
I'm new to indexeddb. Let's say I put several objects to indexed db:
transaction.objectStore("some_store").put(some_object, some_key);
Now I want to get all keys from that object store. Is that possible? If yes, how?
Share Improve this question asked Mar 14, 2013 at 16:05 mnowotkamnowotka 17.3k20 gold badges91 silver badges139 bronze badges3 Answers
Reset to default 3Possible as Kristof said by using openCursor method. It is not efficient because requesting value cursor object might involve de-serialization.
You should also note that, your put method return primary key of the inserted object.
Currently, if you want very efficient keys retrive, index the keyPath for in-line key object store. For out-of-line object store you are out of luck. Using index, you can retrive keys as follow:
transaction.objectStore("some_store").index('id').openKeyCursor(); // here id is primary key path
There is a bug report for requesting openKeyCursor method directly object store. Hopefully next IndexedDB spec will have it.
There is a IDBObjectStore.getAllKeys() method, which will return all keys from an object store.
For more information about this method see: https://developer.mozilla/en-US/docs/Web/API/IDBObjectStore/getAllKeys
You could use this together with the IDBObjectStore.getAll() method to bine the results.
The drawback is that no data should be added to the store between executing those methods.
You will need to use the openCursor method to retrieve al records 1 by 1. Only getting the keys isn't possible.