pub struct SQLxMiddleware<DB>{ /* private fields */ }Expand description
This middleware holds a pool of SQLx database connections, and automatically hands each tide::Request a connection, which may transparently be either a database transaction, or a direct pooled database connection.
By default, transactions are used for all http methods other than GET and HEAD.
When using this, use the SQLxRequestExt extenstion trait to get the connection.
§Example
use sqlx::Acquire; // Or sqlx::prelude::*;
use sqlx::postgres::Postgres;
use tide_sqlx::SQLxMiddleware;
use tide_sqlx::SQLxRequestExt;
let mut app = tide::new();
app.with(SQLxMiddleware::<Postgres>::new("postgres://localhost/a_database").await?);
app.at("/").post(|req: tide::Request<()>| async move {
let mut pg_conn = req.sqlx_conn::<Postgres>().await;
sqlx::query("SELECT * FROM users")
.fetch_optional(pg_conn.acquire().await?)
.await;
Ok("")
});Implementations§
Trait Implementations§
Source§impl<DB> AsRef<Pool<DB>> for SQLxMiddleware<DB>
impl<DB> AsRef<Pool<DB>> for SQLxMiddleware<DB>
Source§impl<DB> Clone for SQLxMiddleware<DB>
impl<DB> Clone for SQLxMiddleware<DB>
Source§fn clone(&self) -> SQLxMiddleware<DB>
fn clone(&self) -> SQLxMiddleware<DB>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<DB> Debug for SQLxMiddleware<DB>
impl<DB> Debug for SQLxMiddleware<DB>
Source§impl<DB> From<Pool<DB>> for SQLxMiddleware<DB>
impl<DB> From<Pool<DB>> for SQLxMiddleware<DB>
Source§impl<State, DB> Middleware<State> for SQLxMiddleware<DB>
impl<State, DB> Middleware<State> for SQLxMiddleware<DB>
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
req: Request<State>,
next: Next<'life1, State>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
req: Request<State>,
next: Next<'life1, State>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Asynchronously handle the request, and return a response.
Auto Trait Implementations§
impl<DB> Freeze for SQLxMiddleware<DB>
impl<DB> !RefUnwindSafe for SQLxMiddleware<DB>
impl<DB> Send for SQLxMiddleware<DB>
impl<DB> Sync for SQLxMiddleware<DB>
impl<DB> Unpin for SQLxMiddleware<DB>
impl<DB> !UnwindSafe for SQLxMiddleware<DB>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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