Trait Statement

Source
pub trait Statement: Send + Sealed {
    type Output: Send;

    // Required methods
    fn execute<S: SqlExecutor>(
        self,
        connection: &S,
    ) -> Result<Self::Output, S::Error>;
    fn execute_mut<S: SqlExecutorMut>(
        self,
        connection: &mut S,
    ) -> Result<Self::Output, S::Error>;
    fn execute_async<S: SqlExecutorAsync>(
        self,
        connection: &mut S,
    ) -> impl Future<Output = Result<Self::Output, S::Error>> + Send;

    // Provided methods
    fn then<Q: Statement>(self, statement: Q) -> Then<Self, Q>
       where Self: Sized { ... }
    fn pipe<Q: StatementWithInput<Input = Self::Output> + Send>(
        self,
        statement: Q,
    ) -> Pipe<Self, Q>
       where Self: Sized { ... }
    fn spanned(self, span: Span) -> TracedStatement<Self>
       where Self: Sized { ... }
    fn spanned_in_current(self) -> TracedStatement<Self>
       where Self: Sized { ... }
}
Expand description

Basic abstraction that defers the execution of a SQL statement in order to reduce the duplication of sync and async code. Basic composability and chaining are also included.

The Send requirement is in theory not required for sync implementations, but this is not intended to be used outside of the scope of this crate.

Required Associated Types§

Source

type Output: Send

Output of this statement.

Required Methods§

Source

fn execute<S: SqlExecutor>( self, connection: &S, ) -> Result<Self::Output, S::Error>

Execute the statement and return the result.

§Errors

If the statement fails, return error.

Source

fn execute_mut<S: SqlExecutorMut>( self, connection: &mut S, ) -> Result<Self::Output, S::Error>

Execute the statement and return the result.

§Errors

If the statement fails, return error.

Source

fn execute_async<S: SqlExecutorAsync>( self, connection: &mut S, ) -> impl Future<Output = Result<Self::Output, S::Error>> + Send

Execute the statement and return the result.

§Errors

If the statement fails, return error.

Provided Methods§

Source

fn then<Q: Statement>(self, statement: Q) -> Then<Self, Q>
where Self: Sized,

If this statement succeeds, then execute the next statement.

Source

fn pipe<Q: StatementWithInput<Input = Self::Output> + Send>( self, statement: Q, ) -> Pipe<Self, Q>
where Self: Sized,

if the current statement succeeds, then execute the next statement with output of the current Statement.

Source

fn spanned(self, span: Span) -> TracedStatement<Self>
where Self: Sized,

Instrument the current statement with the given Span

Source

fn spanned_in_current(self) -> TracedStatement<Self>
where Self: Sized,

Instrument the current statement with currently active Span

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<Q: Statement> Statement for Option<Q>

Source§

type Output = Option<<Q as Statement>::Output>

Source§

fn execute<S: SqlExecutor>( self, connection: &S, ) -> Result<Self::Output, S::Error>

Source§

fn execute_mut<S: SqlExecutorMut>( self, connection: &mut S, ) -> Result<Self::Output, S::Error>

Source§

async fn execute_async<S: SqlExecutorAsync>( self, connection: &mut S, ) -> Result<Self::Output, S::Error>

Implementors§