#diesel #tide #middleware #transaction #postgresql

tide-diesel

Tide middleware for Diesel pooled connections & transactions

3 releases

0.1.2 Feb 15, 2022
0.1.1 Feb 7, 2022
0.1.0 Feb 7, 2022

#1326 in HTTP server

BlueOak-1.0.0

6KB
68 lines

tide-diesel

Tide middleware for Diesel pooled connections & transactions.


A Tide middleware which holds a pool of Diesel database connections, and automatically hands each tide::Request a connection, which may transparently be either a database transaction, or a direct pooled database connection.

When using this, use the DieselRequestExt extenstion trait to get the connection.

Examples

Basic

#[async_std::main]
async fn main() -> anyhow::Result<()> {
    use tide_diesel::DieselRequestExt;

    let mut app = tide::new();
    app.with(DieselMiddleware::new("postgres://localhost/a_database").await?);

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

        Ok("")
    });
    Ok(())
}

License

Licensed under the BlueOak Model License 1.0.0Contributions via DCO 1.1

Dependencies

~14–27MB
~409K SLoC