-
Notifications
You must be signed in to change notification settings - Fork 128
Don't consume ConnectionLike when executing queries #103
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
Comments
Hi. Yeah, this issue is already mentioned (see here) and I'm planning to fix it. I suggest you to use an instance of async fn execute_queries(
pool: Pool,
sql: String,
mut rx: Receiver<Params>,
) -> super::Result<()> {
// Next query loop
while let Some(params) = rx.recv().await {
// Query retry loop
loop {
let conn = pool.get_conn().await?;
match conn.prep_exec(&sql, params.clone()).await {
// Query suceeded.
Ok(res) => break,
// Query failed: wait 3 seconds then retry query
Err(err @ Error::Driver(_)) | Err(err @ Error::Server(_)) => {
println!("Error: {}", err);
delay_for(Duration::from_secs(3)).await;
continue;
}
// Entire connection failed
Err(err) => panic!("Placeholder for more sophisticated reconnect logic I have in actual code.")
}
}
}
Ok(())
} Pool will try to return most recently used connection in |
@nicoburns, new non-consuming API is available in v0.24.0-alpha. Could you, please, test it? (api docs) |
Seems to be working for me. Good work fixing this one. I thought it was going to be months, but in fact it only took you one! |
I want to do something like the following:
However, this is not possible because
stmt.execute
consumesstmt
, and does not return it in the error case. In the case of success it is possible to reuse the preparedstmt
, but it's awkward and involves reassigning the variable as implemented in thebatch
method.Could we change
execute
and similar methods to take&mut self
rather thanself
? This would make reusing connections/prepared statements possible in the case of errors, and make even the success case more ergonomic.The text was updated successfully, but these errors were encountered: