Provide something similar to @FetchRequest for hooking SwiftUI views to Blackbird databases
jackpal opened this issue · comments
The idea is something equivalent to CoreData's @FetchRequest.
As I understand it, the thing you need to do is use https://www.sqlite.org/c3ref/update_hook.html to implement https://developer.apple.com/documentation/swiftui/dynamicproperty
GRDBQuery does this, and supposedly is db-wrapper-agnostic, so maybe people can already use GRDBQuery with Blackbird...
Good idea. On it.
You could use a sqlite3_update_hook
per DynamicProperty
where you need it, rather than wrap it in the global ChangeReporter
class and then unwrap each change.
You would also need to hook each active connection and watch the sqlite file for out of process changes (e.g. via NSFileCoordinator
) to get similar functionality to @FetchRequest
when automaticallyMergesChangesFromParent
is enabled.
Good idea on the external-change filesystem watching. I did that in FCModel with a dispatch source on the file — I'll see what I can do here.
Since my ChangeReporter
system is already based on sqlite3_update_hook
, I'd rather keep funneling the logic through that — I don't really want to expose the internal SQLite database-handle pointer outside of the actor.
Just added external-change filesystem watching.