Skip to content

Instance Method

addRollbackObserver(lifetime:_:)

Register an observer for the SQLite rollback hook.
func addRollbackObserver(lifetime: SQLiteObserverLifetime, _ callback: @escaping SQLiteConnection.SQLiteRollbackHookCallback) async throws -> SQLiteHookToken

Parameters

lifetime

The observer lifetime behavior. See SQLiteObserverLifetime for details. Use scoped for automatic cleanup on token deallocation, or pinned for explicit cleanup only.

callback

Closure 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.