Skip to content

Instance Method

addAuthorizerObserver(lifetime:_:)

Register an observer for the SQLite authorizer hook.
func addAuthorizerObserver(lifetime: SQLiteObserverLifetime, _ callback: @escaping SQLiteConnection.SQLiteAuthorizerObserver) 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 authorization events occur.

Return Value

A SQLiteHookToken that removes the observer when canceled.

Discussion

Authorizer observers perform pure observation (logging, metrics, auditing) without influencing access control decisions. They are notified only if the authorizer validator (if any) has not denied the operation.

let token = connection.addAuthorizerObserver(lifetime: .pinned) { [weak self] event in
    self?.logger.info("Database access: \(event.action) on \(event.parameter1 ?? "N/A")")
}

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.