Diesel, R2D2 and connection not ok

Hi everyone. I don't understand this error:

.....first::models::Person(&conn)
^^^^^ the trait diesel::Connection is not implemented for std::result::Result<diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>, r2d2::Error>

I get a connection with the following code:


db.rs
use lazy_static::lazy_static;

use diesel::{
    r2d2::{Pool, ConnectionManager},
    pg::PgConnection
};

type PgPool = Pool<ConnectionManager<PgConnection>>;

pub struct Values {
    pub db_connection: PgPool,
}

lazy_static! {
   pub static ref VALUES: Values = {
       Values {
           db_connection: PgPool::builder()
               .max_size(8)
               .build(ConnectionManager::new("postgres://postgres:rnpvz8@localhost:5432/db"))
               .expect("failed to create db connection_pool")
       }
   };
}
 let conn = db::VALUES.db_connection.get();

    let user = persons
    .filter(id.eq(idparam))
    .first::<models::Person>(&conn)
    .optional()?;

Pool::get returns a Result<PooledConnection<_>, Error>, since the pool could fail to provide a connection within its configured timeout. You need to handle that error (by unwrapping or returning or otherwise.)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.