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

AnyOf on multiple columns

Open FrankCastelijns opened this issue 3 years ago • 1 comments

I know it's possible to use AnyOf on compound indexes like so:

db.people
  .where('[firstName+lastName]').anyOf([
    ["Foo", "Bar"],
    ["Baz", "Qux"]
  ]).toArray();

And i know this same approach works on compound indexes with more then 2 indexes, but is there any way to avoid sending all permutations of the indata?

For instance, if i'm interested in index1 IN [a,b] and index2 IN [c,d] and index3 IN [e,f], is there a way to avoid doing

where('[index1+index2+index3]').anyOf([[a,c,e],[a,d,e],[a,c,f],[a,d,f],[b,c,e],[b,d,e],[b,c,f,],[b,d,f]])

And do something akin to where('[index1+index2+index3]').anyOf([a,b],[c,d][e,f]) instead?

Because the amount of permutations we need to send with multiple variables balloons out of control quite fast in certain use cases.

FrankCastelijns avatar Oct 08 '21 07:10 FrankCastelijns

I see the use case. Such algorithm could be possible (but currently not part of dexie's toolkit right now). This kind of query can also be achieved by indexing each field individually, query each index with Collection.primaryKeys() and then load the objects from the intersection between the primary key results. There's an updated a sample on how to do that in the docs of Collection.primaryKeys().

dfahlander avatar Oct 22 '21 12:10 dfahlander