Open ursusursus opened 1 year ago
SQLite is certainly capable of database observation. Check out GRDB's ValueObservation for ready-made Combine publishers.
// Connect to the database
let dbQueue = ...
// Define an observation for the tracked value(s).
let observation = ValueObservation.tracking { db in
// Fetch anything you want, from as many tables as needed
return ...
}
// Turn the observation into a Combine publisher
let publisher = observation.publisher(in: dbQueue)
// Be notified of all changes, until the subscription is cancelled.
let cancellable = publisher.sink(
receiveCompletion: { completion in ... },
receiveValue: { value in
print("Fresh database value: \(value)")
})
@ursusursus Can you explain a bit more what you're after?
@jberkel I basically want observable queries, that is to get the current result of the query as first emit, and then subsequent emits as the underlying data changes. In other words, query over time.
Alright. See #686 for a related discussion, which unfortunately fizzled out (there was a user who mentioned opening a PR, but nothing materialized).
Reactive database is needed in reactive architecture. I don't see any Combine bindings provided. Is there some sort of data change listener I could adapt myself to Combine?