Skip to content

Instance Method

setCommitValidator(lifetime:_:)

Register a validator for SQLite commit events (can veto commits).
func setCommitValidator(lifetime: SQLiteObserverLifetime, _ callback: @escaping SQLiteConnection.SQLiteCommitValidator) 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 validator when canceled.

Discussion

Commit validators can examine the transaction and decide whether to allow or deny the commit. Use this for business rule validation, constraints, or access control.

let token = connection.setCommitValidator(lifetime: .pinned) { [weak self] event in
    // Perform validation logic here
    return self?.businessRules.validate(event) == true ? .allow : .deny
}

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.