Crates.io | roa-diesel |
lib.rs | roa-diesel |
version | 0.6.0 |
source | src |
created_at | 2020-03-03 14:59:42.913924 |
updated_at | 2022-01-17 11:10:47.667403 |
description | diesel integration with roa framework |
homepage | https://github.com/Hexilee/roa/wiki |
repository | https://github.com/Hexilee/roa |
max_upload_size | |
id | 214936 |
size | 14,485 |
This crate provides diesel integration with roa framework.
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(())
}
A context extension to execute diesel query asynchronously.
Refer to integration example for more use cases.