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§
sourcetype EnsureTransactionFuture: Future<Output = Result<TransactionGuard<'executor>, Error>> + Send
type EnsureTransactionFuture: Future<Output = Result<TransactionGuard<'executor>, Error>> + Send
A future producing a TransactionGuard
returned by ensure_transaction
Required Methods§
sourcefn execute<'data, 'result, Q>(
self,
query: String,
values: Vec<Value<'data>>
) -> Q::Result<'result>where
Q: QueryStrategy,
'executor: 'result,
'data: 'result,
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![]);
sourcefn ensure_transaction(
self
) -> BoxFuture<'executor, Result<TransactionGuard<'executor>, Error>>
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.