Instance Method
addCommitObserver(lifetime:_:)
Register a pure observer for SQLite commit events (cannot veto commits).
func addCommitObserver(lifetime: SQLiteObserverLifetime, _ callback: @escaping SQLiteConnection.SQLiteCommitObserver) async throws -> SQLiteHookToken
Parameters
lifetimeThe observer lifetime behavior. See
SQLiteObserverLifetimefor details. Usescopedfor automatic cleanup on token deallocation, orpinnedfor explicit cleanup only.callbackClosure to invoke when commit events occur.
Return Value
A SQLiteHookToken that removes the observer when canceled.
Discussion
Commit observers are for logging, metrics, and other side effects that should not interfere with the commit process. They cannot veto commits.
let token = connection.addCommitObserver(lifetime: .pinned) { [weak self] event in
self?.logger.info("Transaction committed: \(event)")
self?.metrics.increment("commits")
}
Important
Registration is safe from any thread. Callbacks are invoked on SQLite’s internal thread; hop to your own actor or event loop as needed.