Search code examples
dexie

Dexiejs advanced search


I am building a inventory app. I have few search fields (part no, manufacturer etc..). I have been trying to build the search based on the input fields. But nothing seems to be working. Things i tried.

db.version(1).stores({
  parts: "++id,partno,description,category,manufacturer,cost,qty,add_date,condition,location"
});

Search 1:

var searchParams = { 'partno': 'md101', 'manufacturer': 'apple', 'category': 'notebook'}

Search 1:

var searchParams = { 'condition': 'new', 'category': 'notebook'}

Worked, but case sensitive. can i make it case insensitive?:

db.parts.where(search); 

Failed:

var fields = Object.keys(search);
var values = Object.values(search)
db.parts.where(fields).equals(values);

Please help me to figure this out. Documentation didn't help

Thank you.


Solution

  • db.parts.where({
      partno: 'md101',
      manufacturer: 'apple',
      category: 'notebook'
    }).toArray().then(result => console.log(result);
    

    The above query will make an logical and between the criterias and match exact.

    To match by case, try the following :

    db.parts.where('partno').equalsIgnoreCase('md101')
      .and(part=>
        part manufacturer &&
        part manufacturer.toLowerCase() === 'apple' &&
        part.category &&
        part.category.toLowerCase() === 'notebook')
     .toArray()
      .then(result => console.log (result))
    

    What we do here is utilizing the most spread index only and filter out the rest manually.