pub trait SessionHook: Send + Sync {
// Provided methods
fn before_query(&self, _ctx: &HookContext) -> Result<()> { ... }
fn after_query(&self, _ctx: &HookContext, _metrics: &QueryMetrics) { ... }
fn before_commit(&self, _ctx: &CommitHookContext) -> Result<()> { ... }
fn after_commit(&self, _ctx: &CommitHookContext, _result: &CommitResult) { ... }
}Expand description
Trait for session lifecycle hooks.
Implement this trait to intercept queries and commits at the session level.
Hooks are stored as Arc<dyn SessionHook> and can be shared across sessions
and templates.
§Failure Semantics
before_query: ReturningErraborts the query withHookRejected.after_query: Infallible — panics are caught and logged.before_commit: ReturningErraborts the commit withHookRejected.after_commit: Infallible — panics are caught and logged.
Provided Methods§
Sourcefn before_query(&self, _ctx: &HookContext) -> Result<()>
fn before_query(&self, _ctx: &HookContext) -> Result<()>
Called before a query is executed. Return Err to reject the query.
Sourcefn after_query(&self, _ctx: &HookContext, _metrics: &QueryMetrics)
fn after_query(&self, _ctx: &HookContext, _metrics: &QueryMetrics)
Called after a query completes. Panics are caught and logged.
Sourcefn before_commit(&self, _ctx: &CommitHookContext) -> Result<()>
fn before_commit(&self, _ctx: &CommitHookContext) -> Result<()>
Called before a transaction is committed. Return Err to reject the commit.
Sourcefn after_commit(&self, _ctx: &CommitHookContext, _result: &CommitResult)
fn after_commit(&self, _ctx: &CommitHookContext, _result: &CommitResult)
Called after a transaction is successfully committed. Panics are caught and logged.