Skip to content

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

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