Sqlx Acquire causes issue with axum handler when using transactions. #4319
-
|
Whenever I try to call a function using Acquire in my axum handler and I am try to use a transaction, the axum handler starts giving me error. But if I pass a PgPool to it my handler works fine. Is there anyway to fix this? The axum handler error is not helpful and using the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
The trait error comes from Grab a connection inside the fn and run against that: async fn create_docs<'c, A>(conn: A) -> Result<(), sqlx::Error>
where
A: Acquire<'c, Database = Postgres> + Send,
{
let mut conn = conn.acquire().await?;
sqlx::query("...").execute(&mut *conn).await?;
Ok(())
}Then call |
Beta Was this translation helpful? Give feedback.
-
This was the solution. So, I have just decided to continue with |
Beta Was this translation helpful? Give feedback.
This was the solution. So, I have just decided to continue with
&mut PgConnection. Hopefully, the bug is fixed with the diagnostics soon. So, we don't have to use this solution.