aaronpowell / db.js

db.js is a wrapper for IndexedDB to make it easier to work against
http://aaronpowell.github.com/db.js/
MIT License
818 stars 142 forks source link

index["openKeyCursor"] is undefined #157

Open shantanuthatte opened 8 years ago

shantanuthatte commented 8 years ago

See https://jsfiddle.net/fok7w86x/2/

Breaks on: https://github.com/aaronpowell/db.js/blob/master/dist/db.js#L288

Fails on Chrome 47.0.2526.111 (64-bit) and Firefox

aaronpowell commented 8 years ago

This looks like a bug in the API that is being surfaced, keys shouldn't be available on all if you don't specify the indexName. The reason for this that openKeyCursor which is used exists on IDBIndex not IDBStore which is used when you don't provide an index (see: https://www.w3.org/TR/IndexedDB/#widl-IDBIndex-openKeyCursor-IDBRequest-any-range-IDBCursorDirection-direction).

I'm not quite sure how best to handle this for the API :confused:

shantanuthatte commented 8 years ago

Sorry for the briefness, of the issue. I just wanted to get people here involved, and make sure I wasn't doing anything dumb.

Strangely enough it works in Chrome 48.0.2564.97 m (64-bit) on Windows And failed on Chrome 47.0.2526.111 (64-bit) on Ubuntu And works on Firefox 44 on Windows. And fails on Firefox 44 on Mac.

shantanuthatte commented 8 years ago

So, in light of this bug, how can I get the entire list of keys?

aaronpowell commented 8 years ago

Because you need to specify the index that you want the key's of the usage that you had doesn't really make sense, you're saying you want the keys, but not where you want them from.

Judging from your usage I'm going to guess that you want the "primary keys", aka all the id's, so to do that you need to "name" the index, like I have here:

http://jsbin.com/pokehe/edit?js,console,output

shantanuthatte commented 8 years ago

Hey,

Thanks for that! Worked like a charm.

Also, I seem to run into another issue,

s.people.query('name').only('Aaron').all().keys().execute()

returns, ['Aaron','Aaron',...]. How can I search/filter by index and then get the ids? Is using filter the only way for this?

aaronpowell commented 8 years ago

If you're just wanting the keyPath for an object store you need to make a named index, as I did with the people object store in the above demo.

shantanuthatte commented 8 years ago

Well, I did create indexes on both name and id. What I'm trying to do is to get id for all people with name as Aaron.

aaronpowell commented 8 years ago

Have you got an example?

brettz9 commented 8 years ago

As far as the original question, I think this is no longer an issue because, per the latest draft spec and in at least Chrome and Firefox, IDBStore now has openKeyCursor too...

brettz9 commented 8 years ago

Could we close this? Neither Chrome nor Firefox are failing on the originally reported issue. I think another issue could be filed if @shantanuthatte still has the other question/issue, but I've added the following with data to demonstrate how to get the IDs:

http://jsbin.com/tazekubujo/1/edit?html,js,console,output