pub struct DbTransactionMiddleware { /* private fields */ }Available on crate feature
sea-orm only.Expand description
A middleware for automatically creating and managing
sea_orm::DatabaseTransactions for incoming
requests.
Implementations§
Source§impl DbTransactionMiddleware
impl DbTransactionMiddleware
Sourcepub fn new(db: DatabaseConnection) -> Self
pub fn new(db: DatabaseConnection) -> Self
Create a new DbTransactionMiddleware.
Sourcepub fn with_check_fn<F>(self, check_fn: F) -> Self
pub fn with_check_fn<F>(self, check_fn: F) -> Self
Use a custom function to check if a response is successful.
By default a response is considered successful iff it is neither a client error (400-499) nor a server error (500-599).
§Example
use poem::{EndpointExt, Route};
use poem_ext::db::DbTransactionMiddleware;
let app = Route::new().nest("/", api_service).with(
// commit only if the response status is "200 OK", otherwise rollback the transaction
DbTransactionMiddleware::new(db_connection).with_check_fn(|response| response.is_ok()),
);Trait Implementations§
Source§impl Debug for DbTransactionMiddleware
impl Debug for DbTransactionMiddleware
Source§impl<E: Endpoint> Middleware<E> for DbTransactionMiddleware
impl<E: Endpoint> Middleware<E> for DbTransactionMiddleware
Source§fn combine<T>(self, other: T) -> CombineMiddleware<Self, T, E>
fn combine<T>(self, other: T) -> CombineMiddleware<Self, T, E>
Create a new middleware by combining two middlewares. Read more
Source§fn combine_if<T>(
self,
enable: bool,
other: T,
) -> EitherMiddleware<Self, CombineMiddleware<Self, T, E>, E>
fn combine_if<T>( self, enable: bool, other: T, ) -> EitherMiddleware<Self, CombineMiddleware<Self, T, E>, E>
Auto Trait Implementations§
impl Freeze for DbTransactionMiddleware
impl !RefUnwindSafe for DbTransactionMiddleware
impl Send for DbTransactionMiddleware
impl Sync for DbTransactionMiddleware
impl Unpin for DbTransactionMiddleware
impl !UnwindSafe for DbTransactionMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more