pub trait QueryMonitor: Send + Sync {
// Required method
fn on_query_complete(
&self,
ctx: &QueryContext,
duration: Duration,
result: &QueryResult,
);
// Provided methods
fn on_query_start(&self, _ctx: &QueryContext) { ... }
fn on_slow_query(&self, _ctx: &QueryContext, _duration: Duration) { ... }
}Expand description
Trait for monitoring SQL query execution.
Implement this trait to collect metrics, log queries, or integrate with observability systems.
Required Methods§
Sourcefn on_query_complete(
&self,
ctx: &QueryContext,
duration: Duration,
result: &QueryResult,
)
fn on_query_complete( &self, ctx: &QueryContext, duration: Duration, result: &QueryResult, )
Called after a query completes (success or failure).
§Arguments
ctx- Query context informationduration- Time taken to execute the queryresult- The result of the query
Provided Methods§
Sourcefn on_query_start(&self, _ctx: &QueryContext)
fn on_query_start(&self, _ctx: &QueryContext)
Called before a query is executed.
Default implementation does nothing.
Sourcefn on_slow_query(&self, _ctx: &QueryContext, _duration: Duration)
fn on_slow_query(&self, _ctx: &QueryContext, _duration: Duration)
Called when a slow query is detected.
Default implementation does nothing. Override to add alerting.