Fix again
This commit is contained in:
parent
5c93253877
commit
d14e4a2160
@ -204,7 +204,7 @@ impl MockDatabaseTrait for MockDatabase {
|
|||||||
|
|
||||||
impl MockRow {
|
impl MockRow {
|
||||||
/// Get a value from the [MockRow]
|
/// Get a value from the [MockRow]
|
||||||
pub fn try_get_by<T, I: crate::ColIdx>(&self, index: I) -> Result<T, DbErr>
|
pub fn try_get<T, I: crate::ColIdx>(&self, index: I) -> Result<T, DbErr>
|
||||||
where
|
where
|
||||||
T: ValueType,
|
T: ValueType,
|
||||||
{
|
{
|
||||||
@ -212,14 +212,12 @@ impl MockRow {
|
|||||||
T::try_from(self.values.get(index).unwrap().clone())
|
T::try_from(self.values.get(index).unwrap().clone())
|
||||||
.map_err(|e| DbErr::Type(e.to_string()))
|
.map_err(|e| DbErr::Type(e.to_string()))
|
||||||
} else if let Some(index) = index.as_usize() {
|
} else if let Some(index) = index.as_usize() {
|
||||||
let (_, value) =
|
let (_, value) = self.values.iter().nth(*index).ok_or_else(|| {
|
||||||
self.values
|
DbErr::Query(RuntimeErr::Internal(format!(
|
||||||
.iter()
|
"Column at index {} not found",
|
||||||
.nth(*index)
|
index
|
||||||
.ok_or(DbErr::Query(RuntimeErr::Internal(format!(
|
)))
|
||||||
"Column at index {} not found",
|
})?;
|
||||||
index
|
|
||||||
))))?;
|
|
||||||
T::try_from(value.clone()).map_err(|e| DbErr::Type(e.to_string()))
|
T::try_from(value.clone()).map_err(|e| DbErr::Type(e.to_string()))
|
||||||
} else {
|
} else {
|
||||||
unreachable!("Missing ColIdx implementation for MockRow");
|
unreachable!("Missing ColIdx implementation for MockRow");
|
||||||
@ -701,10 +699,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
let mocked_row = row.into_mock_row();
|
let mocked_row = row.into_mock_row();
|
||||||
|
|
||||||
let a_id = mocked_row.try_get::<i32>("A_id");
|
let a_id = mocked_row.try_get::<i32, _>("A_id");
|
||||||
assert!(a_id.is_ok());
|
assert!(a_id.is_ok());
|
||||||
assert_eq!(1, a_id.unwrap());
|
assert_eq!(1, a_id.unwrap());
|
||||||
let b_id = mocked_row.try_get::<i32>("B_id");
|
let b_id = mocked_row.try_get::<i32, _>("B_id");
|
||||||
assert!(b_id.is_ok());
|
assert!(b_id.is_ok());
|
||||||
assert_eq!(2, b_id.unwrap());
|
assert_eq!(2, b_id.unwrap());
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ macro_rules! try_getable_all {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -296,7 +296,7 @@ macro_rules! try_getable_unsigned {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -331,7 +331,7 @@ macro_rules! try_getable_mysql {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -377,7 +377,7 @@ macro_rules! try_getable_date_time {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -476,7 +476,7 @@ impl TryGetable for Decimal {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -527,7 +527,7 @@ impl TryGetable for BigDecimal {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -571,7 +571,7 @@ impl TryGetable for u32 {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -614,7 +614,7 @@ mod postgres_array {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -702,7 +702,7 @@ mod postgres_array {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
#[allow(unused_variables)]
|
#[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());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
}),
|
}),
|
||||||
@ -994,7 +994,7 @@ where
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => row
|
QueryResultRow::Mock(row) => row
|
||||||
.try_get_by::<serde_json::Value, I>(idx)
|
.try_get::<serde_json::Value, I>(idx)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
debug_print!("{:#?}", e.to_string());
|
debug_print!("{:#?}", e.to_string());
|
||||||
err_null_idx_col(idx)
|
err_null_idx_col(idx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user