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