Trait Executor

Source
pub trait Executor<'executor> {
    type EnsureTransactionFuture: Future<Output = Result<TransactionGuard<'executor>, Error>> + Send;

    // Required methods
    fn execute<'data, 'result, Q>(
        self,
        query: String,
        values: Vec<Value<'data>>,
    ) -> Q::Result<'result>
       where Q: QueryStrategy,
             'executor: 'result,
             'data: 'result;
    fn dialect(&self) -> DBImpl;
    fn ensure_transaction(
        self,
    ) -> BoxFuture<'executor, Result<TransactionGuard<'executor>, Error>>;
}
Expand description

Some kind of database connection which can execute queries

This trait is implemented by the database connection itself as well as transactions.

Required Associated Types§

Source

type EnsureTransactionFuture: Future<Output = Result<TransactionGuard<'executor>, Error>> + Send

A future producing a TransactionGuard returned by ensure_transaction

Required Methods§

Source

fn execute<'data, 'result, Q>( self, query: String, values: Vec<Value<'data>>, ) -> Q::Result<'result>
where Q: QueryStrategy, 'executor: 'result, 'data: 'result,

Execute a query

db.execute::<All>("SELECT * FROM foo;".to_string(), vec![]);
Source

fn dialect(&self) -> DBImpl

Get the executor’s sql dialect.

Source

fn ensure_transaction( self, ) -> BoxFuture<'executor, Result<TransactionGuard<'executor>, Error>>

Ensure a piece of code is run inside a transaction using a TransactionGuard.

In generic code an Executor might and might not be a [&mut Transaction]. But sometimes you’d want to ensure your code is run inside a transaction (for example bulk inserts).

This method solves this by producing a type which is either an owned or borrowed Transaction depending on the Executor it is called on.

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.

Implementors§

Source§

impl<'executor> Executor<'executor> for &'executor Database

Source§

type EnsureTransactionFuture = Pin<Box<dyn Future<Output = Result<TransactionGuard<'executor>, Error>> + Send + 'executor>>

Source§

impl<'executor> Executor<'executor> for &'executor mut Transaction

Source§

impl<'executor> Executor<'executor> for DynamicExecutor<'executor>

Source§

type EnsureTransactionFuture = Pin<Box<dyn Future<Output = Result<TransactionGuard<'executor>, Error>> + Send + 'executor>>