8 releases

0.6.0 Jan 17, 2022
0.5.0 Apr 2, 2020
0.5.0-rc.2 Mar 31, 2020

#2098 in Database interfaces

31 downloads per month

MIT license

180KB
3.5K SLoC

Stable Test codecov Rust Docs Crate version Download License: MIT

This crate provides diesel integration with roa framework.

AsyncPool

A context extension to access r2d2 pool asynchronously.

use roa::{Context, Result};
use diesel::sqlite::SqliteConnection;
use roa_diesel::Pool;
use roa_diesel::preload::*;
use diesel::r2d2::ConnectionManager;

#[derive(Clone)]
struct State(Pool<SqliteConnection>);

impl AsRef<Pool<SqliteConnection>> for State {
    fn as_ref(&self) -> &Pool<SqliteConnection> {
        &self.0
    }
}

async fn get(ctx: Context<State>) -> Result {
    let conn = ctx.get_conn().await?;
    // handle conn
    Ok(())
}

SqlQuery

A context extension to execute diesel query asynchronously.

Refer to integration example for more use cases.

Dependencies

~13–21MB
~329K SLoC