#async-context #diesel #postgresql #pool #connection-manager #r2d2 #wrapper

helge

Tiny wrapper around r2d2::Pool and diesel ConnectionManager to ease use in async contexts

6 releases (3 stable)

3.0.0 Sep 1, 2023
2.0.0 Aug 29, 2022
2.0.0-rc.1 Jul 23, 2022
2.0.0-rc.0 May 12, 2022
0.1.0 Nov 19, 2021

#1306 in Database interfaces

31 downloads per month

MIT license

7KB
102 lines

helge

Helge is a tiny wrapper around r2d2::Pool and diesel ConnectionManager to provide a simple way to use diesel postgres with r2d2 in an async context.


Example


let helge = Helge::<diesel::PgConnection>::new("postgres://localhost/somedatabase")?;
helge.query(|conn| {
    diesel::insert_into(users::table)
        .values(&NewUser {
            name: String::from("Helge"),
        })
        .execute(conn)
}).await?;

License: MIT


lib.rs:

Helge is a tiny wrapper around r2d2::Pool and diesel ConnectionManager to provide a simple way to use diesel postgres with r2d2 in an async context.


Example

use diesel::prelude::*;
use helge::{Error, Helge};

diesel::table! {
    users {
	    id -> Integer,
	    name -> Varchar,
    }
}

#[derive(Debug, Insertable)]
#[diesel(table_name = users)]
struct NewUser {
    name: String,
}


async fn query() -> Result<(), helge::Error> {
  let helge = Helge::<diesel::PgConnection>::new("postgres://localhost/somedatabase")
                           .expect("connecting Helge");
  helge.query(|conn| {
      diesel::insert_into(users::table)
          .values(&NewUser {
              name: String::from("Helge"),
          })
          .execute(conn)
  }).await;
  Ok(())
}

Dependencies

~5–13MB
~119K SLoC