Skip to main content

SessionHook

Trait SessionHook 

Source
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: Returning Err aborts the query with HookRejected.
  • after_query: Infallible — panics are caught and logged.
  • before_commit: Returning Err aborts the commit with HookRejected.
  • after_commit: Infallible — panics are caught and logged.

Provided Methods§

Source

fn before_query(&self, _ctx: &HookContext) -> Result<()>

Called before a query is executed. Return Err to reject the query.

Source

fn after_query(&self, _ctx: &HookContext, _metrics: &QueryMetrics)

Called after a query completes. Panics are caught and logged.

Source

fn before_commit(&self, _ctx: &CommitHookContext) -> Result<()>

Called before a transaction is committed. Return Err to reject the commit.

Source

fn after_commit(&self, _ctx: &CommitHookContext, _result: &CommitResult)

Called after a transaction is successfully committed. Panics are caught and logged.

Implementors§