Is there no way to perform a WhereClause.startsWith() on a compound index? The following snippets are from this fiddle.
db.version(1).stores({
friends: '++id,first,last,[first+last],age'
});
//...
db.friends.add({first: "Mickey", last: "Mouse", age: 42});
//...
// Expected the following to return Mickey Mouse..but it returns nothing.
return db.friends
.where('[first+last]')
.startsWith('M')
.toArray();
The following variants were also tried, but to no avail:
// Pass an array of items - this behavior is implied by
// http://dexie.org/docs/Compound-Index.html
return db.friends
.where('[first+last]')
.startsWith(['M', 'M'])
.toArray();
// Use startsWithAnyOf
return db.friends
.where('[first+last]')
.startsWithAnyOf(['M', 'M'])
.toArray();
No, but startsWith() is actually just sugar for between(prefixString, prefixString + '\uffff').
So lets say you want to search for documents where type="email" and name starts with "a", you could express it like
db.documents.where('[type+name]').between(
["email", "a"],
["email", "a\uffff"])
...assuming you've indexed "[type+name]".
@dfahlander this should be added in the docs 馃槃
Most helpful comment
No, but startsWith() is actually just sugar for between(prefixString, prefixString + '\uffff').
So lets say you want to search for documents where type="email" and name starts with "a", you could express it like
...assuming you've indexed "[type+name]".