-
Notifications
You must be signed in to change notification settings - Fork 5
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
Multi index querying doesn't seem to be supported. #85
Comments
This here seems to be the issue: https://github.com/mydea/ember-indexeddb/blob/master/addon/services/indexed-db.js#L567 should have a predicate |
Hmm, the line you quoted is about Compound Index, but I believe you are talking about MultiEntry Index. I have not added any special support for MultiEntry indices so far. However, looking through the Dexie docs, it appears you should be able to solve this specific usecase by simply querying for To be able to have if (keys.length === 1) {
let key = keys[0];
if (typeOf(query[key]) === 'array') {
let values = query[key];
let result = db[type].where(key).equals(values.shift());
while(values.length > 0) {
result.and(key).equals(values.shift());
}
return result.distinct();
}
return db[type].where(key).equals(query[key]);
} That seems like it should work, but I've just written that from the top of my head. I'd love to accept a PR with that change, ideally tested - if you want to tackle that, I'd love to guide you if necessary! |
Hmm, I was thinking it more like an SQL in a statement like so:
So it's more like an or. |
This stuff here: https://github.com/mydea/ember-indexeddb/blob/master/addon/services/indexed-db.js#L610 Not intended for multi indexes? |
Taking an approach like this so far: // Else, filter manually
return Object.entries(query)
.reduce(
(query, [queryKey, queryValue]) => {
let index = indexMap[queryKey];
let isMulti = index.multi && isArray(queryValue);
if (!query) {
return isMulti
? db[type].where(queryKey).anyOf(...queryValue)
: db[type].where(queryKey).equals(queryValue);
} else {
let predicate = isMulti
? (item) => get(item, queryKey).any(_ => queryValue.includes(_))
: (item) => get(item, queryKey) === queryValue;
return query.and(predicate);
}
}, null); Seems to be working, curious, have you had any success with relationships between objects? Do they need to be async false? |
Opened a PR for initial comment. |
Will think about how to test. |
Setup like so:
Can see that the db is loaded as expected:
However, the store does not return anything:
What am I missing.
The text was updated successfully, but these errors were encountered: