db.js icon indicating copy to clipboard operation
db.js copied to clipboard

index["openKeyCursor"] is undefined

Open shantanuthatte opened this issue 9 years ago • 10 comments

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

shantanuthatte avatar Feb 01 '16 08:02 shantanuthatte

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:

aaronpowell avatar Feb 01 '16 09:02 aaronpowell

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 avatar Feb 01 '16 16:02 shantanuthatte

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

shantanuthatte avatar Feb 01 '16 16:02 shantanuthatte

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

aaronpowell avatar Feb 01 '16 22:02 aaronpowell

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?

shantanuthatte avatar Feb 08 '16 07:02 shantanuthatte

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.

aaronpowell avatar Feb 08 '16 10:02 aaronpowell

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.

shantanuthatte avatar Feb 08 '16 10:02 shantanuthatte

Have you got an example?

aaronpowell avatar Feb 09 '16 05:02 aaronpowell

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 avatar Mar 27 '16 15:03 brettz9

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

brettz9 avatar Apr 11 '16 16:04 brettz9