diff --git a/src/executor/query.rs b/src/executor/query.rs index abc6ca6d9..ce3ae4c88 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -463,7 +463,6 @@ try_getable_unsigned!(u16); try_getable_mysql!(u64); try_getable_all!(f32); try_getable_all!(f64); -try_getable_all!(String); try_getable_all!(Vec); #[cfg(feature = "with-json")] @@ -705,6 +704,51 @@ impl TryGetable for u32 { } } +impl TryGetable for String { + #[allow(unused_variables)] + fn try_get_by(res: &QueryResult, idx: I) -> Result { + match &res.row { + #[cfg(feature = "sqlx-mysql")] + QueryResultRow::SqlxMySql(row) => row + .try_get::>, _>(idx.as_sqlx_mysql_index()) + .map_err(|e| sqlx_error_to_query_err(e).into()) + .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))) + .map(|bytes| { + String::from_utf8(bytes).map_err(|e| { + DbErr::TryIntoErr { + from: "Vec", + into: "String", + source: Box::new(e), + } + .into() + }) + })?, + #[cfg(feature = "sqlx-postgres")] + QueryResultRow::SqlxPostgres(row) => row + .try_get::, _>(idx.as_sqlx_postgres_index()) + .map_err(|e| sqlx_error_to_query_err(e).into()) + .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))), + #[cfg(feature = "sqlx-sqlite")] + QueryResultRow::SqlxSqlite(row) => row + .try_get::, _>(idx.as_sqlx_sqlite_index()) + .map_err(|e| sqlx_error_to_query_err(e).into()) + .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))), + #[cfg(feature = "mock")] + QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + err_null_idx_col(idx) + }), + #[cfg(feature = "proxy")] + QueryResultRow::Proxy(row) => row.try_get(idx).map_err(|e| { + debug_print!("{:#?}", e.to_string()); + err_null_idx_col(idx) + }), + #[allow(unreachable_patterns)] + _ => unreachable!(), + } + } +} + #[allow(dead_code)] fn err_null_idx_col(idx: I) -> TryGetError { TryGetError::Null(format!("{idx:?}"))