-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot run two fetches within a transaction #257
Comments
pub async fn run1(mut tx: &mut sqlx::Transaction<PoolConnection<PgConnection>>) -> sqlx::Result<u64> {
sqlx::query("abc")
.fetch(&mut *tx);
sqlx::query("abc")
.fetch(&mut *tx);
Ok(3)
} The key is you need to manually re-borrow the transaction. This is normally done implicitly by Rust. It's not in this case due to A tip, you can define your function like this: pub async fn run1(conn: &mut PgConnection) and call as such (assuming that run1(&mut tx) This works because |
Great, thanks a lot. |
@mehcode Is it possible to define a function that can take either |
I'm encountering this same issue but it also applies to Ideally I'd like to make my function generic so it can take any RefExecutor, but if I want to make two fetches within the same function, I have to add the |
If your function has a parameter of say |
As for generalizing over Pool or Connection, that's difficult without GATs in Rust because we're talking about For now, I would recommend acquiring connections manually and then passing those around (so don't pass the pool around to functions that may want a transaction). It's trivial to generalize between |
Hi,
I want to run multiple fetches within a single transaction.
But I get an error
Is it currently possible to have multiple fetches within a single transaction?
The text was updated successfully, but these errors were encountered: