Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiEntry + Array keyPath #36

Open
inexorabletash opened this issue Aug 10, 2015 · 2 comments
Open

Allow multiEntry + Array keyPath #36

inexorabletash opened this issue Aug 10, 2015 · 2 comments

Comments

@inexorabletash
Copy link
Member

Imported from https://www.w3.org/Bugs/Public/show_bug.cgi?id=21836

Currently, the spec for IDBObjectStore.createIndex has:

If keyPath is a sequence and multiEntry is set, throw an InvalidAccessError exception.

This disallows some interesting use cases, although the expected behavior in more complex cases is unclear. Per @sicking:

Consider a multiEntry index with keyPath ["a", "b"]

It's pretty intuitive that storing a value like:

{
  id: 1,
  a: "apple",
  b: "orange"
}

would add the following entries to the index:

"apple" -> 1
"orange" -> 1

But what would storing the following value result in?

{
  id: 1,
  a: ["apple", "x"],
  b: ["orange", "y"]
}

Would this result in the following entries

A)
["apple", "x"] -> 1
["orange", "y"] -> 1

or

B)
"apple" -> 1
"x" -> 1
"orange" -> 1
"y" -> 1

or

C)
["apple", "orange"] -> 1
["x", "y"] -> 1

@inexorabletash
Copy link
Member Author

inexorabletash commented Jul 22, 2019

If we ever tackle this, we also need to specify the behavior when a subkey is missing, e.g.:

store.createIndex('by_name', ['name', 'alias'], {multiEntry: true});
store.add({name: 'Luke Cage', alias: 'Power Man'}); // OK; two entries
store.add({name: 'Jessica Jones'}); // ???

If multiEntry were false, this throws since alias does not resolve and the compound key can't have a hole. But here it would be logical (?) for there to be only a single entry.

@theSherwood
Copy link

@inexorabletash
This would be very useful. I currently have an app in dire need of it. Though, wouldn't this index make the most sense?:

D)
["apple", "orange"] -> 1
["apple", "y"] -> 1
["x", "orange"] -> 1
["x", "y"] -> 1

Of course, this risks a combinatorial explosion. But it seems to me that the combination of multiEntry and compound indices ought to be the cartesian product. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants