Skip to main content

Executor

Trait Executor 

Source
pub trait Executor {
    type Rows<'a>: RowStream + 'a
       where Self: 'a;
    type Statement<'a>: PreparedStatement<Rows<'a> = Self::Rows<'a>> + 'a
       where Self: 'a;

    // Required methods
    fn driver(&self) -> Driver;
    fn query(
        &mut self,
        sql: &str,
    ) -> impl Future<Output = Result<Self::Rows<'_>>> + Send;
    fn query_prepared_source<P>(
        &mut self,
        sql: &str,
        params: &P,
    ) -> impl Future<Output = Result<Self::Rows<'_>>> + Send
       where P: ParamSource + Sync + ?Sized;
    fn prepare(
        &mut self,
        sql: &str,
    ) -> impl Future<Output = Result<Self::Statement<'_>>> + Send;
}
Expand description

Something that can run SQL.

This is the trait behind query and prepare. [Connection], [Pool], crate::PoolTransaction, crate::PooledConnection, crate::PooledTransaction, and crate::Transaction all implement it.

Use this trait when you want generic code that can work with either a plain connection, a pool, or a transaction.

Rows<'a> is the stream type returned while the executor is borrowed for 'a. Statement<'a> is the prepared statement type returned from Self::prepare.

Required Associated Types§

Source

type Rows<'a>: RowStream + 'a where Self: 'a

Row stream returned by this executor.

Source

type Statement<'a>: PreparedStatement<Rows<'a> = Self::Rows<'a>> + 'a where Self: 'a

Prepared statement returned by this executor.

Required Methods§

Source

fn driver(&self) -> Driver

Returns the selected database driver.

Source

fn query( &mut self, sql: &str, ) -> impl Future<Output = Result<Self::Rows<'_>>> + Send

Runs SQL without explicit bound parameters.

For SQL with parameters, most code should use query or Self::prepare instead of calling Self::query_prepared_source directly.

Source

fn query_prepared_source<P>( &mut self, sql: &str, params: &P, ) -> impl Future<Output = Result<Self::Rows<'_>>> + Send
where P: ParamSource + Sync + ?Sized,

Runs SQL with a borrowed parameter source.

This is the low-level path used by Query when parameters were bound. Most callers should not need to use it directly.

Source

fn prepare( &mut self, sql: &str, ) -> impl Future<Output = Result<Self::Statement<'_>>> + Send

Prepares SQL for repeated use.

Reuse this when the same SQL runs many times on the same executor.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl Executor for &Pool

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PoolStatement where Self: 'a

Source§

impl Executor for &mut Connection

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = Statement<'a> where Self: 'a

Source§

impl Executor for &mut Pool

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PoolStatement where Self: 'a

Source§

impl Executor for &mut PoolTransaction

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PooledStatement<'a> where Self: 'a

Source§

impl Executor for &mut PooledConnection

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PooledStatement<'a> where Self: 'a

Source§

impl Executor for &mut PooledTransaction<'_>

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PooledStatement<'a> where Self: 'a

Source§

impl Executor for &mut Transaction<'_>

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = Statement<'a> where Self: 'a

Source§

impl Executor for Connection

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = Statement<'a> where Self: 'a

Source§

impl Executor for Pool

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PoolStatement where Self: 'a

Source§

impl Executor for PoolTransaction

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PooledStatement<'a> where Self: 'a

Source§

impl Executor for PooledConnection

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PooledStatement<'a> where Self: 'a

Source§

impl Executor for PooledTransaction<'_>

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = PooledStatement<'a> where Self: 'a

Source§

impl Executor for Transaction<'_>

Source§

type Rows<'a> = Rows<'a> where Self: 'a

Source§

type Statement<'a> = Statement<'a> where Self: 'a