| 1 | use std::iter::{Extend, IntoIterator}; |
| 2 | |
| 3 | #[derive(Debug, Default)] |
| 4 | pub struct MySqlQueryResult { |
| 5 | pub(super) rows_affected: u64, |
| 6 | pub(super) last_insert_id: u64, |
| 7 | } |
| 8 | |
| 9 | impl MySqlQueryResult { |
| 10 | pub fn last_insert_id(&self) -> u64 { |
| 11 | self.last_insert_id |
| 12 | } |
| 13 | |
| 14 | pub fn rows_affected(&self) -> u64 { |
| 15 | self.rows_affected |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | impl Extend<MySqlQueryResult> for MySqlQueryResult { |
| 20 | fn extend<T: IntoIterator<Item = MySqlQueryResult>>(&mut self, iter: T) { |
| 21 | for elem in iter { |
| 22 | self.rows_affected += elem.rows_affected; |
| 23 | self.last_insert_id = elem.last_insert_id; |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | #[cfg(feature = "any")] |
| 28 | /// This conversion attempts to save last_insert_id by converting to i64. |
| 29 | impl From<MySqlQueryResult> for sqlx_core::any::AnyQueryResult { |
| 30 | fn from(done: MySqlQueryResult) -> Self { |
| 31 | sqlx_core::any::AnyQueryResult { |
| 32 | rows_affected: done.rows_affected(), |
| 33 | last_insert_id: done.last_insert_id().try_into().ok(), |
| 34 | } |
| 35 | } |
| 36 | } |