diff --git a/src/database/mock.rs b/src/database/mock.rs index 744fa234..734ed39c 100644 --- a/src/database/mock.rs +++ b/src/database/mock.rs @@ -204,7 +204,7 @@ impl MockDatabaseTrait for MockDatabase { impl MockRow { /// Get a value from the [MockRow] - pub fn try_get_by(&self, index: I) -> Result + pub fn try_get(&self, index: I) -> Result where T: ValueType, { @@ -212,14 +212,12 @@ impl MockRow { T::try_from(self.values.get(index).unwrap().clone()) .map_err(|e| DbErr::Type(e.to_string())) } else if let Some(index) = index.as_usize() { - let (_, value) = - self.values - .iter() - .nth(*index) - .ok_or(DbErr::Query(RuntimeErr::Internal(format!( - "Column at index {} not found", - index - ))))?; + let (_, value) = self.values.iter().nth(*index).ok_or_else(|| { + DbErr::Query(RuntimeErr::Internal(format!( + "Column at index {} not found", + index + ))) + })?; T::try_from(value.clone()).map_err(|e| DbErr::Type(e.to_string())) } else { unreachable!("Missing ColIdx implementation for MockRow"); @@ -701,10 +699,10 @@ mod tests { ); let mocked_row = row.into_mock_row(); - let a_id = mocked_row.try_get::("A_id"); + let a_id = mocked_row.try_get::("A_id"); assert!(a_id.is_ok()); assert_eq!(1, a_id.unwrap()); - let b_id = mocked_row.try_get::("B_id"); + let b_id = mocked_row.try_get::("B_id"); assert!(b_id.is_ok()); assert_eq!(2, b_id.unwrap()); } diff --git a/src/executor/query.rs b/src/executor/query.rs index 69c101ea..bbe585f9 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -258,7 +258,7 @@ macro_rules! try_getable_all { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -296,7 +296,7 @@ macro_rules! try_getable_unsigned { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -331,7 +331,7 @@ macro_rules! try_getable_mysql { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -377,7 +377,7 @@ macro_rules! try_getable_date_time { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -476,7 +476,7 @@ impl TryGetable for Decimal { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -527,7 +527,7 @@ impl TryGetable for BigDecimal { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -571,7 +571,7 @@ impl TryGetable for u32 { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -614,7 +614,7 @@ mod postgres_array { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -702,7 +702,7 @@ mod postgres_array { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get_by(idx).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx) }), @@ -994,7 +994,7 @@ where } #[cfg(feature = "mock")] QueryResultRow::Mock(row) => row - .try_get_by::(idx) + .try_get::(idx) .map_err(|e| { debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx)