I was wondering, does SQLite.swift
have the capability, to detect & notify table data change?
(Similar to what is offered by NSFetchedResultsController
, to detect & notify entity data change)
For GRDB.swift, it offers the capability to observe table data change.
private func configureDataSourceContent() {
switch playerOrdering {
case .byName:
playersCancellable = AppDatabase.shared.observePlayersOrderedByName(
onError: { error in fatalError("Unexpected error: \(error)") },
onChange: { [weak self] players in
guard let self = self else { return }
self.updateDataSourceContent(with: players)
})
case .byScore:
playersCancellable = AppDatabase.shared.observePlayersOrderedByScore(
onError: { error in fatalError("Unexpected error: \(error)") },
onChange: { [weak self] players in
guard let self = self else { return }
self.updateDataSourceContent(with: players)
})
}
}
SQLite itself does provide low level Data Change Notification Callbacks (https://www.sqlite.org/c3ref/update_hook.html).
Does SQLite.swift
offer anything out of the box, by building on the top of sqlite3_update_hook
? If not, is it possible for us to custom build such solution?
Thanks.