Skip to main content

HandlerContext

Trait HandlerContext 

Source
pub trait HandlerContext: Sealed {
    // Required methods
    fn db(&self) -> ForgeDb;
    fn db_conn(&self) -> DbConn<'_>;
}
Expand description

Base trait for all Forge handler contexts.

Provides access to the database pool — the one capability shared by every handler kind (queries, mutations, jobs, crons, daemons, webhooks, workflows, MCP tools).

Sealed: only forge-core can implement this trait.

Required Methods§

Source

fn db(&self) -> ForgeDb

Database handle with automatic db.query tracing spans.

Works directly with sqlx compile-time checked macros:

sqlx::query_as!(Item, "SELECT * FROM items")
    .fetch_all(ctx.db())
    .await?
Source

fn db_conn(&self) -> DbConn<'_>

Unified connection handle for shared helper functions.

Prefer this over db() when writing helpers that need to work with both pool-backed and transaction-backed contexts.

Implementors§