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.

Implementors§

source§

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

§

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

source§

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

source§

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

§

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