Trait tide_sqlx::SQLxRequestExt[][src]

pub trait SQLxRequestExt {
    #[must_use]
    fn sqlx_conn<'req, 'async_trait, DB>(
        &'req self
    ) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'req, ConnectionWrapInner<DB>>> + Send + 'async_trait>>
    where
        DB: Database,
        DB::Connection: Send + Sync + 'static,
        'req: 'async_trait,
        DB: 'async_trait,
        Self: 'async_trait
; }

An extension trait for tide::Request which does proper unwrapping of the connection from req.ext().

Required methods

#[must_use]
fn sqlx_conn<'req, 'async_trait, DB>(
    &'req self
) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'req, ConnectionWrapInner<DB>>> + Send + 'async_trait>> where
    DB: Database,
    DB::Connection: Send + Sync + 'static,
    'req: 'async_trait,
    DB: 'async_trait,
    Self: 'async_trait, 
[src]

Get the SQLx connection for the current Request.

This will return a “write” guard from a read-write lock. Under the hood this will transparently be either a postgres transaction or a direct pooled connection.

This will panic with an expect message if the SQLxMiddleware has not been run.

Example

use sqlx::Acquire; // Or sqlx::prelude::*;

use tide_sqlx::SQLxRequestExt;

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("")
});
Loading content...

Implementations on Foreign Types

impl<T: Send + Sync + 'static> SQLxRequestExt for Request<T>[src]

Loading content...

Implementors

Loading content...