Lighter-swift / Lighter

Swift APIs for SQLite: Type-safe down to the schema. Very, very, fast. Dependency free.
https://lighter-swift.github.io/documentation/lighter/
MIT License
459 stars 12 forks source link

TBD: Add a change notification center #6

Open helje5 opened 2 years ago

helje5 commented 2 years ago

This can very quickly become non-Light, and maybe it shouldn't be actually done, but it might be useful to have a simple notification center that can broadcast DB change notifications. I had the feeling that it is better to let the user do this in own code as required.

I'd probably do this as a simple closure the user can hook up to anything he wants, like:

MyDatabase.onChange { some enum in  }

It quickly becomes a Pony, users might want to know the exact tables or IDs affected and so on, which sometimes isn't even possible w/ SQL itself. Transactions also complicate the matter.

Maybe rather something for Heavier. So a basic mechanism might be helpful.

PadraigK commented 2 years ago

Something straightforward that forwards notifications from https://www.sqlite.org/c3ref/update_hook.html would be helpful imho.

Since that callback gives the table id, and is called once for each changed rowid, it could associate changes with tables/views nicely and even group rowids together per transaction.