Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indexeddb get all keys from object store

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?

like image 995
mnowotka Avatar asked Sep 20 '25 21:09

mnowotka


1 Answers

Possible 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.

like image 79
Kyaw Tun Avatar answered Sep 22 '25 09:09

Kyaw Tun