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
lifetimeThe observer lifetime behavior. See
SQLiteObserverLifetimefor details. Usescopedfor automatic cleanup on token deallocation, orpinnedfor explicit cleanup only.callbackClosure 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.