The sqlx documentation says the following:
The
execute
query finalizer returns the number of affected rows, if any, and drops all received results. In addition, there arefetch
,fetch_one
,fetch_optional
, andfetch_all
to receive results.The
Query
type returned fromsqlx::query
will returnRow<'conn>
from the database. Column values can be accessed by ordinal or by name withrow.get()
. As theRow
retains an immutable borrow on the connection, only oneRow
may exist at a time.
Is there any way get both the rows_affected
and the rows themselves?
I tried running the same query twice in a transaction that I rollback intentionally, but I am already in the middle of a transaction when I receive the sql statement, and I cannot run two transactions in parallel.
Is there a way to do it without running it twice?
I am using rust, the latest sqlx and postgres as the database.
You'll also need the
futures
crate:Then you can do shenanigans like this:
This will return