pub trait Executor: Send + Sync {
// Required method
fn transaction<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Transaction<'life0>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}Expand description
Anything that can execute queries — Db,
Connection, or Transaction.
This trait is dyn-compatible. The generic [exec](dyn Executor::exec)
method lives on dyn Executor and accepts any typed
Statement<T>.
Required Methods§
Sourcefn transaction<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Transaction<'life0>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn transaction<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Transaction<'life0>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Starts a (potentially nested) transaction.
Takes &mut self so the executor is exclusively borrowed while the
transaction is open. This prevents statements from accidentally
executing on the parent handle rather than through &mut tx, which
would bypass the transaction.
Implementations§
Source§impl dyn Executor + '_
impl dyn Executor + '_
Sourcepub async fn exec<T>(
&mut self,
stmt: Statement<T>,
) -> Result<<T as Load>::Output, Error>where
T: Load,
pub async fn exec<T>(
&mut self,
stmt: Statement<T>,
) -> Result<<T as Load>::Output, Error>where
T: Load,
Execute a typed Statement and deserialize the result.
This is the primary entry point for running queries, inserts, updates,
and deletes. The return type is determined by the statement’s type
parameter T:
Statement<List<M>>returnsVec<M>.Statement<M>returnsM.Statement<Option<M>>returnsOption<M>.Statement<()>returns().
Most users call exec on the query/update/delete builders directly
(e.g., Query::exec) rather than calling
this method, but it is available for working with Statement values
directly.
§Examples
use toasty::stmt::{IntoStatement, List, Query};
use toasty::Executor;
let stmt = Query::<List<User>>::all().into_statement();
let executor: &mut dyn Executor = &mut db;
let users: Vec<User> = executor.exec(stmt).await.unwrap();Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".