-
hey, i'm trying to use when using pub struct Db {
client: tokio_postgres::Client,
find_user_statement: tokio_postgres::Statement,
}
pub async fn get_user(db: actix_web::web::Data<Db>, user_id: i32) -> Option<User> {
let row = db
.client
.query_one(&db.find_user_statement, &[&user_id.clone()]) // it doesn't require client ref to be mutable
.await
.ok();
row.map(|row| User {
id: row.get(0),
name: row.get(1),
})
} same with pub struct Db {
connection: diesel_async::AsyncPgConnection,
}
pub async fn get_user(
db: actix_web::web::Data<Db>,
user_id: i32,
) -> Result<models::User, diesel::result::Error> {
use crate::schema::users::dsl::*;
let user = users
.filter(id.eq(user_id))
.first::<models::User>(&mut db.connection) // error: expects mutable connection ref
.await?;
Ok(user)
} i could wrap connection into async mutex or use connection pool, but that would neglect whole idea of reusing same connection for multiple queries simultaneously (pipelining) so, is postgres pipelining possible with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Pipelining is not supported yet. I cannot say if future versions will support pipelining as this requires quite a bit design work first to see if a common interface could abstract over the fact that a backend supports pipelining or not. |
Beta Was this translation helpful? Give feedback.
-
for anyone else finding this discussion in the future: at this point pipelining has officially been implemented at least for Postgres (see https://github.com/weiznich/diesel_async/blob/v0.5.0/src/pg/mod.rs#L850-L868) |
Beta Was this translation helpful? Give feedback.
Pipelining is not supported yet. I cannot say if future versions will support pipelining as this requires quite a bit design work first to see if a common interface could abstract over the fact that a backend supports pipelining or not.