Dexie.js: startsWith on compound index?

Created on 2 Jun 2017  路  2Comments  路  Source: dfahlander/Dexie.js

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();
question

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

db.documents.where('[type+name]').between(
    ["email", "a"],
    ["email", "a\uffff"])

...assuming you've indexed "[type+name]".

All 2 comments

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 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Script47 picture Script47  路  3Comments

muthuveerappan picture muthuveerappan  路  3Comments

devolarium picture devolarium  路  3Comments

remusao picture remusao  路  3Comments

dfahlander picture dfahlander  路  4Comments