The sqlx documentation says the following:
The
executequery finalizer returns the number of affected rows, if any, and drops all received results. In addition, there arefetch,fetch_one,fetch_optional, andfetch_allto receive results.The
Querytype returned fromsqlx::querywill returnRow<'conn>from the database. Column values can be accessed by ordinal or by name withrow.get(). As theRowretains an immutable borrow on the connection, only oneRowmay 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
futurescrate:Then you can do shenanigans like this:
This will return