From 9b9918efc4dc59905d9aaeb8d18c0d33342ae93d Mon Sep 17 00:00:00 2001 From: Marco Napetti Date: Thu, 26 Aug 2021 15:50:53 +0200 Subject: [PATCH 1/4] Remove impl TryGetable for Option --- src/executor/query.rs | 242 +++++++++--------------------------------- 1 file changed, 50 insertions(+), 192 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index b7e1d12e6..f0f03c721 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -17,8 +17,22 @@ pub(crate) enum QueryResultRow { Mock(crate::MockRow), } +pub enum TryGetError { + DbErr(DbErr), + Null, +} + +impl From for DbErr { + fn from(e: TryGetError) -> DbErr { + match e { + TryGetError::DbErr(e) => e, + TryGetError::Null => DbErr::Query("error occurred while decoding: Null".to_owned()), + } + } +} + pub trait TryGetable { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result where Self: Sized; } @@ -30,7 +44,7 @@ impl QueryResult { where T: TryGetable, { - T::try_get(self, pre, col) + Ok(T::try_get(self, pre, col)?) } } @@ -51,38 +65,20 @@ impl fmt::Debug for QueryResultRow { // TryGetable // +impl TryGetable for Option { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + match T::try_get(res, pre, col) { + Ok(v) => Ok(Some(v)), + Err(TryGetError::Null) => Ok(None), + Err(e) => Err(e), + } + } +} + macro_rules! try_getable_all { ( $type: ty ) => { impl TryGetable for $type { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); - match &res.row { - #[cfg(feature = "sqlx-mysql")] - QueryResultRow::SqlxMySql(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "sqlx-postgres")] - QueryResultRow::SqlxPostgres(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "sqlx-sqlite")] - QueryResultRow::SqlxSqlite(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?), - } - } - } - - impl TryGetable for Option<$type> { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { let column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] @@ -90,27 +86,24 @@ macro_rules! try_getable_all { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - }, + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), } } } @@ -120,33 +113,7 @@ macro_rules! try_getable_all { macro_rules! try_getable_unsigned { ( $type: ty ) => { impl TryGetable for $type { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); - match &res.row { - #[cfg(feature = "sqlx-mysql")] - QueryResultRow::SqlxMySql(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "sqlx-postgres")] - QueryResultRow::SqlxPostgres(_) => { - panic!("{} unsupported by sqlx-postgres", stringify!($type)) - } - #[cfg(feature = "sqlx-sqlite")] - QueryResultRow::SqlxSqlite(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?), - } - } - } - - impl TryGetable for Option<$type> { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { let column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] @@ -154,6 +121,7 @@ macro_rules! try_getable_unsigned { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(_) => { @@ -164,15 +132,10 @@ macro_rules! try_getable_unsigned { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - }, + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), } } } @@ -182,31 +145,7 @@ macro_rules! try_getable_unsigned { macro_rules! try_getable_mysql { ( $type: ty ) => { impl TryGetable for $type { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); - match &res.row { - #[cfg(feature = "sqlx-mysql")] - QueryResultRow::SqlxMySql(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "sqlx-postgres")] - QueryResultRow::SqlxPostgres(_) => { - panic!("{} unsupported by sqlx-postgres", stringify!($type)) - } - #[cfg(feature = "sqlx-sqlite")] - QueryResultRow::SqlxSqlite(_) => { - panic!("{} unsupported by sqlx-sqlite", stringify!($type)) - } - #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?), - } - } - } - - impl TryGetable for Option<$type> { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { let column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] @@ -214,6 +153,7 @@ macro_rules! try_getable_mysql { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(_) => { @@ -224,13 +164,7 @@ macro_rules! try_getable_mysql { panic!("{} unsupported by sqlx-sqlite", stringify!($type)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - }, + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), } } } @@ -240,31 +174,7 @@ macro_rules! try_getable_mysql { macro_rules! try_getable_postgres { ( $type: ty ) => { impl TryGetable for $type { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); - match &res.row { - #[cfg(feature = "sqlx-mysql")] - QueryResultRow::SqlxMySql(_) => { - panic!("{} unsupported by sqlx-mysql", stringify!($type)) - } - #[cfg(feature = "sqlx-postgres")] - QueryResultRow::SqlxPostgres(row) => { - use sqlx::Row; - row.try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - } - #[cfg(feature = "sqlx-sqlite")] - QueryResultRow::SqlxSqlite(_) => { - panic!("{} unsupported by sqlx-sqlite", stringify!($type)) - } - #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?), - } - } - } - - impl TryGetable for Option<$type> { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { let column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] @@ -276,19 +186,14 @@ macro_rules! try_getable_postgres { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) + .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(_) => { panic!("{} unsupported by sqlx-sqlite", stringify!($type)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - }, + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), } } } @@ -322,83 +227,36 @@ use rust_decimal::Decimal; #[cfg(feature = "with-rust_decimal")] impl TryGetable for Decimal { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { + fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { let column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] QueryResultRow::SqlxMySql(row) => { use sqlx::Row; - row.try_get(column.as_str()) + row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; - row.try_get(column.as_str()) + row.try_get::, _>(column.as_str()) .map_err(crate::sqlx_error_to_query_err) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; - let val: f64 = row + let val: Option = row .try_get(column.as_str()) .map_err(crate::sqlx_error_to_query_err)?; use rust_decimal::prelude::FromPrimitive; - Decimal::from_f64(val) - .ok_or_else(|| DbErr::Query("Failed to convert f64 into Decimal".to_owned())) - } - #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?), - } - } -} - -#[cfg(feature = "with-rust_decimal")] -impl TryGetable for Option { - fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); - match &res.row { - #[cfg(feature = "sqlx-mysql")] - QueryResultRow::SqlxMySql(row) => { - use sqlx::Row; - match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - } - } - #[cfg(feature = "sqlx-postgres")] - QueryResultRow::SqlxPostgres(row) => { - use sqlx::Row; - match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - } - } - #[cfg(feature = "sqlx-sqlite")] - QueryResultRow::SqlxSqlite(_) => { - let result: Result = TryGetable::try_get(res, pre, col); - match result { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } + match val { + Some(v) => Decimal::from_f64(v) + .ok_or_else(|| DbErr::Query("Failed to convert f64 into Decimal".to_owned())), + None => Err(TryGetError::Null) } } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => match row.try_get(column.as_str()) { - Ok(v) => Ok(Some(v)), - Err(e) => { - debug_print!("{:#?}", e.to_string()); - Ok(None) - } - }, + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), } } } From 4dadfd3f5108d93ea8db637123824cadc4567958 Mon Sep 17 00:00:00 2001 From: Marco Napetti Date: Thu, 26 Aug 2021 16:05:12 +0200 Subject: [PATCH 2/4] restore debug_print! for Mock variant --- src/executor/query.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index f0f03c721..12666b7d3 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -103,7 +103,10 @@ macro_rules! try_getable_all { .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + TryGetError::Null + }), } } } @@ -135,7 +138,10 @@ macro_rules! try_getable_unsigned { .and_then(|opt| opt.ok_or_else(TryGetError::Null)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + TryGetError::Null + }), } } } @@ -164,7 +170,10 @@ macro_rules! try_getable_mysql { panic!("{} unsupported by sqlx-sqlite", stringify!($type)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + TryGetError::Null + }), } } } @@ -193,7 +202,10 @@ macro_rules! try_getable_postgres { panic!("{} unsupported by sqlx-sqlite", stringify!($type)) } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + TryGetError::Null + }), } } } @@ -256,7 +268,10 @@ impl TryGetable for Decimal { } } #[cfg(feature = "mock")] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|_| TryGetError::Null), + QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + TryGetError::Null + }), } } } From 344659f517d9de471bd6fb5f588050315f66b64d Mon Sep 17 00:00:00 2001 From: Marco Napetti Date: Thu, 26 Aug 2021 16:50:05 +0200 Subject: [PATCH 3/4] Fix test errors --- src/executor/query.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index 12666b7d3..b1e8b7b3f 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -85,22 +85,22 @@ macro_rules! try_getable_all { QueryResultRow::SqlxMySql(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "mock")] QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { @@ -123,8 +123,8 @@ macro_rules! try_getable_unsigned { QueryResultRow::SqlxMySql(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(_) => { @@ -134,8 +134,8 @@ macro_rules! try_getable_unsigned { QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "mock")] QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { @@ -158,8 +158,8 @@ macro_rules! try_getable_mysql { QueryResultRow::SqlxMySql(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(_) => { @@ -194,8 +194,8 @@ macro_rules! try_getable_postgres { QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) - .and_then(|opt| opt.ok_or_else(TryGetError::Null)) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(_) => { @@ -246,24 +246,26 @@ impl TryGetable for Decimal { QueryResultRow::SqlxMySql(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) - .map_err(crate::sqlx_error_to_query_err) + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) + .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; let val: Option = row .try_get(column.as_str()) - .map_err(crate::sqlx_error_to_query_err)?; + .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))?; use rust_decimal::prelude::FromPrimitive; match val { Some(v) => Decimal::from_f64(v) - .ok_or_else(|| DbErr::Query("Failed to convert f64 into Decimal".to_owned())), + .ok_or_else(|| TryGetError::DbErr(DbErr::Query("Failed to convert f64 into Decimal".to_owned()))), None => Err(TryGetError::Null) } } From 8f0f8a193b25fe8deec1b933b25a8c2af06d0c57 Mon Sep 17 00:00:00 2001 From: Marco Napetti Date: Thu, 26 Aug 2021 19:54:33 +0200 Subject: [PATCH 4/4] Fix clippy lint --- src/executor/query.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index b1e8b7b3f..08728081c 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -86,21 +86,21 @@ macro_rules! try_getable_all { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "mock")] QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { @@ -124,7 +124,7 @@ macro_rules! try_getable_unsigned { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(_) => { @@ -135,7 +135,7 @@ macro_rules! try_getable_unsigned { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "mock")] QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { @@ -159,7 +159,7 @@ macro_rules! try_getable_mysql { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(_) => { @@ -195,7 +195,7 @@ macro_rules! try_getable_postgres { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(_) => { @@ -247,14 +247,14 @@ impl TryGetable for Decimal { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; row.try_get::, _>(column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) - .and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) + .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => {