roa-diesel

Crates.ioroa-diesel
lib.rsroa-diesel
version0.6.0
sourcesrc
created_at2020-03-03 14:59:42.913924
updated_at2022-01-17 11:10:47.667403
descriptiondiesel integration with roa framework
homepagehttps://github.com/Hexilee/roa/wiki
repositoryhttps://github.com/Hexilee/roa
max_upload_size
id214936
size14,485
xixi (Hexilee)

documentation

https://docs.rs/roa-diesel

README

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.

Commit count: 722

cargo fmt