-
It is nice to be able to write code that's independent of current status of connection or transaction and thus function could take executor that is either transaction or connection. Can it be done with this library? It seems that I might be able to ask for connection and then pass transaction that gets converted to underlying connection, but I am not sure. |
Beta Was this translation helpful? Give feedback.
Answered by
blackbeam
Jun 21, 2024
Replies: 1 comment 3 replies
-
Hi. Please look at the following code snippet: pub async fn archive(conn: &mut impl Queryable, id: i32) -> crate::Result<bool> {
// ^^^^^^^^^^^^^^^^^^^^^^^^^ this works for both &mut Conn and &mut Transaction
const QUERY: &str = "UPDATE `ReadingRooms` \
SET `is_archived` = NOT `is_archived` WHERE `id` = ?";
let affected_rows = conn.exec_iter(QUERY, (id,)).await?.affected_rows();
Ok(affected_rows > 0)
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
kulak
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Please look at the following code snippet: