Trait TransactionHandler

Source
pub trait TransactionHandler<DB>: Send + Sync
where DB: DatabaseBackend + Send + Sync + Debug + 'static,
{ type Item; type Error: From<DB::Error> + Send + Sync; // Required method fn execute<'life0, 'async_trait>( self, ctx: &'life0 mut TestContext<DB>, ) -> Pin<Box<dyn Future<Output = Result<Self::Item, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn execute_standalone<'async_trait>( self, backend: DB, ) -> Pin<Box<dyn Future<Output = Result<Self::Item, Self::Error>> + Send + 'async_trait>> where Self: Sized + 'async_trait { ... } fn and_then<F, B>(self, f: F) -> AndThenHandler<DB, Self, B, F> where Self: Sized, B: TransactionHandler<DB, Error = Self::Error> + Send + Sync, F: FnOnce(Self::Item) -> B + Send + Sync + 'static { ... } fn setup<S, Fut, E>( self, setup_fn: S, ) -> impl TransactionHandler<DB, Item = (), Error = Self::Error> where Self: Sized, E: From<DB::Error> + From<Self::Error> + Send + Sync, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, S: FnOnce(&mut <DB::Pool as DatabasePool>::Connection) -> Fut + Send + Sync + 'static { ... } fn with_transaction<F, Fut, E>( self, transaction_fn: F, ) -> impl TransactionHandler<DB, Item = (), Error = Self::Error> where Self: Sized, E: From<DB::Error> + From<Self::Error> + Send + Sync, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static { ... } fn with_db_transaction<F, Fut, E>( self, db: TestDatabaseInstance<DB>, transaction_fn: F, ) -> impl TransactionHandler<DB, Item = TestContext<DB>, Error = Self::Error> where Self: Sized, E: From<DB::Error> + From<Self::Error> + Send + Sync, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static { ... } fn run_with_database<'async_trait>( self, backend: DB, ) -> Pin<Box<dyn Future<Output = Result<TestContext<DB>, Self::Error>> + Send + 'async_trait>> where Self: Sized + 'async_trait { ... } }
Expand description

A trait for handlers that can work with transactions

Required Associated Types§

Source

type Item

The result type of this handler

Source

type Error: From<DB::Error> + Send + Sync

The error type

Required Methods§

Source

fn execute<'life0, 'async_trait>( self, ctx: &'life0 mut TestContext<DB>, ) -> Pin<Box<dyn Future<Output = Result<Self::Item, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the handler with the given context

Provided Methods§

Source

fn execute_standalone<'async_trait>( self, backend: DB, ) -> Pin<Box<dyn Future<Output = Result<Self::Item, Self::Error>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

Execute this handler with a new context

This is a convenience method that creates a new context using the provided database backend and then executes the handler with it.

Source

fn and_then<F, B>(self, f: F) -> AndThenHandler<DB, Self, B, F>
where Self: Sized, B: TransactionHandler<DB, Error = Self::Error> + Send + Sync, F: FnOnce(Self::Item) -> B + Send + Sync + 'static,

Chain two handlers together, where the second handler may depend on the result of the first

Source

fn setup<S, Fut, E>( self, setup_fn: S, ) -> impl TransactionHandler<DB, Item = (), Error = Self::Error>
where Self: Sized, E: From<DB::Error> + From<Self::Error> + Send + Sync, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, S: FnOnce(&mut <DB::Pool as DatabasePool>::Connection) -> Fut + Send + Sync + 'static,

Add a setup operation to this handler

Source

fn with_transaction<F, Fut, E>( self, transaction_fn: F, ) -> impl TransactionHandler<DB, Item = (), Error = Self::Error>
where Self: Sized, E: From<DB::Error> + From<Self::Error> + Send + Sync, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static,

Add a transaction operation to this handler

Source

fn with_db_transaction<F, Fut, E>( self, db: TestDatabaseInstance<DB>, transaction_fn: F, ) -> impl TransactionHandler<DB, Item = TestContext<DB>, Error = Self::Error>
where Self: Sized, E: From<DB::Error> + From<Self::Error> + Send + Sync, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static,

Create a database transaction handler from this handler

Source

fn run_with_database<'async_trait>( self, backend: DB, ) -> Pin<Box<dyn Future<Output = Result<TestContext<DB>, Self::Error>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

Run this handler with a new database instance

Implementors§

Source§

impl<DB> TransactionHandler<DB> for BoxedSetupHandler<DB>
where DB: DatabaseBackend + Send + Sync + Debug + 'static,

Source§

impl<DB> TransactionHandler<DB> for BoxedTransactionHandler<DB>
where DB: DatabaseBackend + Send + Sync + Debug + 'static,

Source§

impl<DB> TransactionHandler<DB> for BoxedTransactionOnlyHandler<DB>
where DB: DatabaseBackend + Send + Sync + Debug + 'static,

Source§

impl<DB> TransactionHandler<DB> for BoxedDatabaseEntryPoint<DB>
where DB: DatabaseBackend + Send + Sync + Debug + 'static,

Source§

impl<DB, A, B, F> TransactionHandler<DB> for AndThenHandler<DB, A, B, F>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, A: TransactionHandler<DB> + Send + Sync, B: TransactionHandler<DB, Error = A::Error> + Send + Sync, F: FnOnce(A::Item) -> B + Send + Sync + 'static,

Source§

impl<DB, F, Fut> TransactionHandler<DB> for DatabaseTransactionHandler<DB, F>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static,

Source§

impl<DB, F, Fut> TransactionHandler<DB> for SetupHandler<DB, F>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, F: FnOnce(&mut <DB::Pool as DatabasePool>::Connection) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static,

Source§

impl<DB, F, Fut> TransactionHandler<DB> for TransactionFnHandler<DB, F>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static,

Source§

impl<DB, F, Fut, E> TransactionHandler<DB> for DbTransactionHandlerWrapper<DB, F, E>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static, E: From<DB::Error> + Send + Sync,

Source§

impl<DB, F, Fut, E> TransactionHandler<DB> for TransactionFnHandlerWrapper<DB, F, E>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, F: FnOnce(&mut <DB as DatabaseBackend>::Connection) -> Fut + Send + Sync + 'static, E: From<DB::Error> + Send + Sync,

Source§

impl<DB, S, Fut, E> TransactionHandler<DB> for SetupHandlerWrapper<DB, S, E>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, Fut: Future<Output = Result<(), DB::Error>> + Send + 'static, S: FnOnce(&mut <DB::Pool as DatabasePool>::Connection) -> Fut + Send + Sync + 'static, E: From<DB::Error> + Send + Sync,