Skip to main content

Executor

Trait Executor 

Source
pub trait Executor {
    type Database: Database;

    // Required methods
    fn connection_state(&self) -> ConnectionState;
    fn execute_many<'this, B>(
        &'this mut self,
        buffer: &mut B,
        cmd: &str,
        cb: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>,
    ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>
       where B: TryExtend<[<Self::Database as Database>::Records<'this>; 1]>;
    fn execute_stmt_many<SC, RV>(
        &mut self,
        sc: SC,
        rv: RV,
        cb: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>,
    ) -> impl Future<Output = Result<<Self::Database as Database>::Records<'_>, <Self::Database as DEController>::Error>>
       where RV: RecordValues<Self::Database>,
             SC: StmtCmd;
    fn ping(
        &mut self,
    ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>;
    fn prepare(
        &mut self,
        cmd: &str,
    ) -> impl Future<Output = Result<u64, <Self::Database as DEController>::Error>>;

    // Provided methods
    fn execute_ignored(
        &mut self,
        cmd: &str,
    ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>> { ... }
    fn execute_none(
        &mut self,
        cmd: &str,
    ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>> { ... }
    fn execute_single(
        &mut self,
        cmd: &str,
    ) -> impl Future<Output = Result<<Self::Database as Database>::Record<'_>, <Self::Database as DEController>::Error>> { ... }
    fn execute_stmt_ignored<SC, RV>(
        &mut self,
        sc: SC,
        rv: RV,
    ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>
       where RV: RecordValues<Self::Database>,
             SC: StmtCmd { ... }
    fn execute_stmt_none<SC, RV>(
        &mut self,
        sc: SC,
        rv: RV,
    ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>
       where RV: RecordValues<Self::Database>,
             SC: StmtCmd { ... }
    fn execute_stmt_single<SC, RV>(
        &mut self,
        sc: SC,
        rv: RV,
    ) -> impl Future<Output = Result<<Self::Database as Database>::Record<'_>, <Self::Database as DEController>::Error>>
       where RV: RecordValues<Self::Database>,
             SC: StmtCmd { ... }
    fn transaction<'this, F, R>(
        &'this mut self,
        fun: impl FnOnce(&'this mut Self) -> F,
    ) -> impl Future<Output = Result<R, <Self::Database as DEController>::Error>>
       where F: Future<Output = Result<(R, &'this mut Self), <Self::Database as DEController>::Error>> { ... }
}
Available on crate feature database only.
Expand description

A connection for executing database commands.

Required Associated Types§

Required Methods§

Source

fn connection_state(&self) -> ConnectionState

Sometimes the backend can discontinue the connection.

Source

fn execute_many<'this, B>( &'this mut self, buffer: &mut B, cmd: &str, cb: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>, ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>
where B: TryExtend<[<Self::Database as Database>::Records<'this>; 1]>,

Execute - Many

Allows the evaluation of severals commands separated by semicolons but nothing is cached or inspected for potential vulnerabilities.

cb returns the most recent record and can be used in case you don’t need to wait for the full set of records potentially reducing some branches, in other words, an optional optimization.

  • Pass &mut () to buffer if you don’t want to populate returned values.
  • There are no statements, as such, returned values are treated as strings.
Source

fn execute_stmt_many<SC, RV>( &mut self, sc: SC, rv: RV, cb: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>, ) -> impl Future<Output = Result<<Self::Database as Database>::Records<'_>, <Self::Database as DEController>::Error>>
where RV: RecordValues<Self::Database>, SC: StmtCmd,

Execute Statement - Many

Executes a single statement automatically binding the values of rv. Expects and returns an arbitrary number of records.

cb returns the most recent record and can be used in case you don’t need to wait for the full set of records potentially reducing some branches, in other words, an optional optimization.

Source

fn ping( &mut self, ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>

Pings the server to signal an active connection

Source

fn prepare( &mut self, cmd: &str, ) -> impl Future<Output = Result<u64, <Self::Database as DEController>::Error>>

Caches the passed command to create a statement, which speeds up subsequent calls that match the same cmd.

The returned integer is an identifier of the added statement.

Provided Methods§

Source

fn execute_ignored( &mut self, cmd: &str, ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>

Execute - Ignored

A version of Executor::execute_many where returned values are ignored. This is the most performant variation.

Source

fn execute_none( &mut self, cmd: &str, ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>

Execute - None

A version of Executor::execute_many where no records are expected.

Source

fn execute_single( &mut self, cmd: &str, ) -> impl Future<Output = Result<<Self::Database as Database>::Record<'_>, <Self::Database as DEController>::Error>>

Execute - Single

A version of Executor::execute_many where a single record is expected.

Source

fn execute_stmt_ignored<SC, RV>( &mut self, sc: SC, rv: RV, ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>
where RV: RecordValues<Self::Database>, SC: StmtCmd,

Execute Statement - Ignored

A version of Executor::execute_stmt_many where returned values are ignored.This is the most performant variation.

Source

fn execute_stmt_none<SC, RV>( &mut self, sc: SC, rv: RV, ) -> impl Future<Output = Result<(), <Self::Database as DEController>::Error>>
where RV: RecordValues<Self::Database>, SC: StmtCmd,

Execute Statement - None

A version of Executor::execute_stmt_many where no records are expected.

Source

fn execute_stmt_single<SC, RV>( &mut self, sc: SC, rv: RV, ) -> impl Future<Output = Result<<Self::Database as Database>::Record<'_>, <Self::Database as DEController>::Error>>
where RV: RecordValues<Self::Database>, SC: StmtCmd,

Execute Statement - Single

A version of Executor::execute_stmt_many where a single record is expected.

Source

fn transaction<'this, F, R>( &'this mut self, fun: impl FnOnce(&'this mut Self) -> F, ) -> impl Future<Output = Result<R, <Self::Database as DEController>::Error>>
where F: Future<Output = Result<(R, &'this mut Self), <Self::Database as DEController>::Error>>,

Makes internal calls to “BEGIN” and “COMMIT”.

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 Executor for ()

Source§

type Database = ()

Source§

fn connection_state(&self) -> ConnectionState

Source§

async fn execute_many<'this, B>( &'this mut self, _: &mut B, _: &str, _: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>, ) -> Result<(), <Self::Database as DEController>::Error>
where B: TryExtend<[<Self::Database as Database>::Records<'this>; 1]>,

Source§

async fn execute_stmt_many<SC, RV>( &mut self, _: SC, _: RV, _: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>, ) -> Result<<Self::Database as Database>::Records<'_>, <Self::Database as DEController>::Error>
where RV: RecordValues<Self::Database>, SC: StmtCmd,

Source§

async fn ping(&mut self) -> Result<(), <Self::Database as DEController>::Error>

Source§

async fn prepare( &mut self, _: &str, ) -> Result<u64, <Self::Database as DEController>::Error>

Source§

impl<T> Executor for &mut T
where T: Executor,

Source§

type Database = <T as Executor>::Database

Source§

fn connection_state(&self) -> ConnectionState

Source§

async fn execute_many<'this, B>( &'this mut self, buffer: &mut B, cmd: &str, cb: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>, ) -> Result<(), <Self::Database as DEController>::Error>
where B: TryExtend<[<Self::Database as Database>::Records<'this>; 1]>,

Source§

async fn execute_stmt_many<SC, RV>( &mut self, sc: SC, rv: RV, cb: impl FnMut(<Self::Database as Database>::Record<'_>) -> Result<(), <Self::Database as DEController>::Error>, ) -> Result<<Self::Database as Database>::Records<'_>, <Self::Database as DEController>::Error>
where RV: RecordValues<Self::Database>, SC: StmtCmd,

Source§

async fn ping(&mut self) -> Result<(), <Self::Database as DEController>::Error>

Source§

async fn prepare( &mut self, cmd: &str, ) -> Result<u64, <Self::Database as DEController>::Error>

Implementors§

Source§

impl<E, EB, S> Executor for MysqlExecutor<E, EB, S>
where E: From<Error>, EB: LeaseMut<ExecutorBuffer>, S: Stream,

Available on crate feature mysql only.
Source§

impl<E, EB, S> Executor for PostgresExecutor<E, EB, S>
where E: From<Error>, EB: LeaseMut<ExecutorBuffer>, S: Stream,

Available on crate feature postgres only.