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()?;