webdb icon indicating copy to clipboard operation
webdb copied to clipboard

live-updating DB queries

Open derhuerst opened this issue 7 years ago • 3 comments

Hey!

What do you think about having live-updating DB queries, as a more user-friendly interface on top of the WebDBTable events put-record and del-record?

An example:

const query = webdb.people.where('lastName').equalsIgnoreCase('roberts')

query.on('put', console.log) // {url, origin, indexedAt, record}
query.on('del', console.log) // {url, origin, indexedAt}

derhuerst avatar Feb 26 '18 14:02 derhuerst

Oh that's interesting. Maybe a method, toEventStream() ?

pfrazee avatar Feb 26 '18 15:02 pfrazee

Oh that's interesting. Maybe a method, toEventStream() ?

I chose an EventEmitter to have an API similar to WebDB and WebDBTable. But maybe a more explicit API is better.

derhuerst avatar Feb 26 '18 15:02 derhuerst

We'll need to internally track any emitting query so that the emit() can be called. I'm fine with it behaving mostly like an EventEmitter but I think the create and destroy will need to be explicitly called by a consumer to avoid leaks.

pfrazee avatar Feb 26 '18 15:02 pfrazee