Skip to main content

Execute

Trait Execute 

Source
pub trait Execute: Query {
    // Provided methods
    fn fetch_all<T: FromRow>(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<Vec<T>, ExecError>> + Send { ... }
    fn fetch_rows(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<Vec<Row>, ExecError>> + Send { ... }
    fn fetch_one<T: FromRow>(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<T, ExecError>> + Send { ... }
    fn fetch_optional<T: FromRow>(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<Option<T>, ExecError>> + Send { ... }
    fn fetch_scalar<T: FromValue>(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<T, ExecError>> + Send { ... }
    fn fetch_scalars<T: FromValue>(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<Vec<T>, ExecError>> + Send { ... }
    fn execute(
        &self,
        db: &(impl Executor + ?Sized),
    ) -> impl Future<Output = Result<ExecResult, ExecError>> + Send { ... }
}
Expand description

The ergonomic verbs, hung on every Query.

Blanket-implemented — use keelson_exec::Execute is the one import that makes q.fetch_all(&db) compile, and db is anything that implements Executor: a pool, a connection, a transaction, or a &dyn Executor. The methods build the query synchronously (the query knows its own dialect), so the returned future borrows only the executor.

This is also the funnel observability lives in (feature tracing): every verb passes through one pair of functions, so no backend can ship uninstrumented and no two backends can drift. Calling Executor::fetch directly bypasses the sugar and the spans together; that path is the escape hatch and is documented as such.

Provided Methods§

Source

fn fetch_all<T: FromRow>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Vec<T>, ExecError>> + Send

Every row, mapped to T.

Source

fn fetch_rows( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Vec<Row>, ExecError>> + Send

Every row, undecoded.

The row-mapper seam Layer 2 needs: a model query decodes the base struct first and then lets its preload mapper mods take the prefixed relation columns out of the same row, so the rows must come back as Rows without an intermediate decode. (fetch_all::<Row> would work but clones every row on the way through FromRow.) Same funnel, same tracing, as every other verb.

Source

fn fetch_one<T: FromRow>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<T, ExecError>> + Send

Exactly one row. Zero rows is ExecError::RowNotFound; a second row is ExecError::TooManyRows — “one” means one.

Source

fn fetch_optional<T: FromRow>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Option<T>, ExecError>> + Send

At most one row. A second row is still ExecError::TooManyRows.

Source

fn fetch_scalar<T: FromValue>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<T, ExecError>> + Send

The first column of the single row — SELECT count(*), or an INSERT … RETURNING id.

A separate verb rather than a blanket FromRow for T: FromValue, which would collide with a type implementing both; the verb is clearer at the call site anyway.

Source

fn fetch_scalars<T: FromValue>( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<Vec<T>, ExecError>> + Send

The first column of every row.

Source

fn execute( &self, db: &(impl Executor + ?Sized), ) -> impl Future<Output = Result<ExecResult, ExecError>> + Send

Run for the side effect.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Q: Query + ?Sized> Execute for Q