Instance Method
addRollbackObserver(lifetime:_:)
Register an observer for the SQLite rollback hook.
func addRollbackObserver(lifetime: SQLiteObserverLifetime, _ callback: @escaping SQLiteConnection.SQLiteRollbackHookCallback) 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 rollback events occur.
Return Value
A SQLiteHookToken that removes the observer when canceled.
Discussion
Fired whenever a transaction is rolled back. Multiple observers can be registered on the same connection.
let token = connection.addRollbackObserver(lifetime: .pinned) { [weak self] event in
self?.logger.info("Transaction was rolled back at \(event.date)")
}
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.