wtulloch / Blazor.IndexedDB

A Blazor library for accessing IndexedDB
MIT License
140 stars 46 forks source link

Getting a record using the index? #7

Closed fulviocanducci closed 5 years ago

fulviocanducci commented 5 years ago

Help please: getting a record using the index?

missing example please

I tried a code and it didn't work

example:

public async Task<IList<T>> AllDoneAsync(bool done)
{            
            return await DbManager.GetAllRecordsByIndex<bool, T>(new StoreIndexQuery<bool>()
            {
                Storename = Storename(),
                AllMatching = true,
                IndexName = "done",
                QueryValue = done            
            });
}
fulviocanducci commented 5 years ago

If you can exemplify this method DbManager.GetAllRecordsByIndex ?

wtulloch commented 5 years ago

Your code is correct the issue is with IndexedDB itself. To put simply IndexedDB does not index on Boolean values. So even though you can create the index it won't be used.

There are a few of ways you can get around this.

  1. change your done property to either an int or string (I have tested this)
  2. Provide an additional property that returns Done as a string or int and set the index on that
  3. Return all of the items and then filter on the Done property.

Hope that helps

fulviocanducci commented 5 years ago

@wtulloch thanks ...