feat: Unify Debug implementations across PgRow, MySqlRow and SqliteRow (#3890)

* Introduce `debug_row` function

* Use `debug_row` to implement `Debug` for `SqliteRow`

* Use `debug_row` in `PgRow`'s `Debug` implementation

* Match `MySqlRow`'s `Debug` implementation
This commit is contained in:
David Cornu
2025-07-06 22:24:07 -04:00
committed by GitHub
parent 9f28837bca
commit 2702b9851a
4 changed files with 47 additions and 25 deletions

View File

@@ -4,10 +4,8 @@ use crate::message::DataRow;
use crate::statement::PgStatementMetadata;
use crate::value::PgValueFormat;
use crate::{PgColumn, PgValueRef, Postgres};
use sqlx_core::row::debug_row;
pub(crate) use sqlx_core::row::Row;
use sqlx_core::type_checking::TypeChecking;
use sqlx_core::value::ValueRef;
use std::fmt::Debug;
use std::sync::Arc;
/// Implementation of [`Row`] for PostgreSQL.
@@ -51,25 +49,8 @@ impl ColumnIndex<PgRow> for &'_ str {
}
}
impl Debug for PgRow {
impl std::fmt::Debug for PgRow {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "PgRow ")?;
let mut debug_map = f.debug_map();
for (index, column) in self.columns().iter().enumerate() {
match self.try_get_raw(index) {
Ok(value) => {
debug_map.entry(
&column.name,
&Postgres::fmt_value_debug(&<PgValueRef as ValueRef>::to_owned(&value)),
);
}
Err(error) => {
debug_map.entry(&column.name, &format!("decode error: {error:?}"));
}
}
}
debug_map.finish()
debug_row(self, f)
}
}