Visiting https://github.com/diesel-rs/r2d2-diesel has a deprecation notice at the top pointing towards the r2d2 module powered by: https://github.com/sfackler/r2d2, which has great documentation on the package. However on our end there is no documentation on how integration with diesel works. Should we document how to properly use this?
The source in diesel specifies "See the [r2d2 documentation] for usage examples." and then points "[r2d2 documentation]" to the same file. Of the three tests in this file, only one actually utilizes diesel, and very minimally: select("foo".into_sql::<Text>());.
Could we add realistic example and perhaps a README for r2d2 functionality, particularly for new users?
Related: #1874
This is one of the main reasons I want to do #1958
@thsowers See: https://github.com/diesel-rs/r2d2-diesel/blob/master/examples/postgres.rs -- adapting it is simple. You just use diesel::r2d2 instead of r2d2.
This is badly needed. I just spent a few hours figuring out that I have to add r2d2 to the "features" in Cargo.toml. If I hadn't found some something about it on the forums I would have never figured it out.
Maybe a small section in http://diesel.rs/guides/
I started making an example project with Actix but got stuck on this compile error
error: the trait bound `i32: diesel::deserialize::FromSql<diesel::sql_types::Uuid, diesel::pg::Pg>` is not satisfied
label: the trait `diesel::deserialize::FromSql<diesel::sql_types::Uuid, diesel::pg::Pg>` is not implemented for `i32`
Has anyone seen this before?
I'm trying to compile this code.
use diesel::prelude::*;
use crate::schema::player;
#[derive(Queryable)]
struct Player {
id: i32,
name: String,
}
#[derive(Insertable)]
#[table_name = "player"]
struct NewPlayer<'a> {
name: &'a str,
}
impl Player {
fn create(conn: &PgConnection, new_player: NewPlayer) -> Self {
diesel::insert_into(player::table)
.values(new_player)
.get_result(conn)
.expect("Error creating player")
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn create_player() {
let pool = get_pool();
// expected reference `&diesel::PgConnection`
// found struct `r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>`
let conn: &PgConnection = pool.get().unwrap();
let new_player = NewPlayer { name: "Jon" };
let result = Player::create(conn, new_player);
assert_eq!(result.name, "Jon")
}
}
pub type PostgresPool = Pool<ConnectionManager<PgConnection>>;
pub fn get_pool() -> PostgresPool {
dotenv().ok();
let url = env::var("DATABASE_URL").expect("no DATABASE_URL found");
let manager = ConnectionManager::<PgConnection>::new(url);
r2d2::Pool::builder()
.build(manager)
.expect("could not build connection pool")
}
With these versions
[dependencies]
diesel = { version = "1.4.5", features = ["postgres", "r2d2"] }
r2d2 = "0.8.9"
@vladinator1000 Please do not comment totally unrelated error messages to existing issues.
Most helpful comment
This is badly needed. I just spent a few hours figuring out that I have to add r2d2 to the "features" in Cargo.toml. If I hadn't found some something about it on the forums I would have never figured it out.
Maybe a small section in http://diesel.rs/guides/