beakerbrowser / webdb

The Web is your database.

Home Page:https://www.npmjs.com/package/@beaker/webdb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

live-updating DB queries

derhuerst opened this issue · 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}

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

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.

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.