dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.48k stars 642 forks source link

find if entity matches a WhereClause #926

Open stutrek opened 4 years ago

stutrek commented 4 years ago

I'm trying to make a set of React hooks for Dexie that load data and watch for updates with Dexie.Observable. You'd use them more or less like this:

// easy with Dexie.Observable
const [ users, isLoadingUsers ] = useTable(db.users);
const [ user3, isLoadingUser3 ] = useItem(db.users, 3);

// less easy
const [daves, isLoadingDaves ] = useCollection(db.users.where('name').equals('dave'));

I have a few crudely conceived ideas over here

The first two are simple because you can check the update from Dexie.Observable against a known table and id, but the where clause is significantly harder. Is there a way to see if an entity matches a where clause?

Thanks

dfahlander commented 4 years ago

I think this one would require a change in where-clause.ts and collection.ts. We would need a testItem(item) method on Collection. To be able to implement that, we need to add more info on the CollectionContext interface.

A pull request that adds a testItem() method on Collection would be very welcome. I will at some point do it regardless, but as I have no time currently to do it, so please help me if you want to have it there.

dfahlander commented 4 years ago

If implementing it, where-clause maybe needs to put some new info about the operator. Specifically, those operators that use algorithms might need to have some complementary information.

stutrek commented 4 years ago

If I get a chance, I absolutely will. However, I need this for a side project and not work so it might take a while. I can also work with just useTable and useItem for now.

The truly difficult part will be offsets.