Trait preroll::prelude::PostgresRequestExt[][src]

pub trait PostgresRequestExt {
    #[must_use]
    fn pg_conn<'req, 'async_trait>(
        &'req self
    ) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'req, ConnectionWrapInner<Postgres>>> + 'async_trait + Send, Global>>
    where
        'req: 'async_trait,
        Self: 'async_trait
; }
This is supported on crate feature postgres only.
Expand description

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

Specialized for Postgres connections.

Required methods

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::postgres::PostgresRequestExt;

app.at("/").post(|req: tide::Request<()>| async move {
    let mut pg_conn = req.pg_conn().await;

    sqlx::query("SELECT * FROM users")
        .fetch_optional(pg_conn.acquire().await?)
        .await;

    Ok("")
});

Implementations on Foreign Types

Implementors