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

pub trait PostgresRequestExt {
#[must_use]    pub 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
; }

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

Specialized for Postgres connections.

Required methods

#[must_use]pub 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, 
[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::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("")
});
Loading content...

Implementations on Foreign Types

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

Loading content...

Implementors

Loading content...