Open darksylinc opened 10 months ago
Hi. There is no such an API because Transaction
doesn't owns the Conn, but borrows it, i.e. there is nothing to unwrap 🤷
Regarding your example - it looks really unnatural to me. It's like someone, for whatever reason, wants to write this HTML:
<div>
<h1>Hello<h2></h1>World</h2>
</div>
Instead of writing correct HTML:
<div>
<h1>Hello</h1><h2>World</h2>
</div>
Anyway. As mentioned in the docs, Transaction is just a convenient wrapper, so, if you really need to write it that way, then your options are:
fn common_func( tx : mut Transaction) {
tx.query_drop("SELECT 1");
tx.query_drop("COMMIT");
tx.query_drop("SELECT 1");
}
START TRANSACTION
, COMMIT
, ROLLBACK
and other relevant directives.
Hi!
I have the following situation (dummy commands to explain the point):
Now the problem is that I wanted to encapsulate some common functionality, so I need to pass the tx and conn variables and ended up with:
The problem is that this does not work because
conn
is already mutably borrowed in tx.Is there a solution to this problem?
AFAIK it is not possible to reuse the Transaction tx after commit/rollback. From what I can tell, this could be solved if I could retrieve the connection again after transaction is dropped.
Something like the following would fix my problem:
Is this already possible? Am I trying to do something that I shouldn't do? Is this is a simply an API oversight?
Of course rust-mysql would need to implement both
commit_with_connection
androllback_with_connection
.Cheers