Skip to content

Commit 2189a2b

Browse files
committed
Add Debug impl for PgRow
1 parent 0aae849 commit 2189a2b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

sqlx-postgres/src/row.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ use crate::message::DataRow;
44
use crate::statement::PgStatementMetadata;
55
use crate::value::PgValueFormat;
66
use crate::{PgColumn, PgValueRef, Postgres};
7-
use std::sync::Arc;
8-
97
pub(crate) use sqlx_core::row::Row;
8+
use sqlx_core::type_checking::TypeChecking;
9+
use sqlx_core::value::ValueRef;
10+
use std::fmt::Debug;
11+
use std::sync::Arc;
1012

1113
/// Implementation of [`Row`] for PostgreSQL.
1214
pub struct PgRow {
@@ -48,3 +50,23 @@ impl ColumnIndex<PgRow> for &'_ str {
4850
.map(|v| *v)
4951
}
5052
}
53+
54+
impl Debug for PgRow {
55+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56+
write!(f, "PgRow ")?;
57+
58+
let mut debug_map = f.debug_map();
59+
for (index, column) in self.columns().iter().enumerate() {
60+
if let Ok(value) = self.try_get_raw(index) {
61+
debug_map.entry(
62+
&column.name,
63+
&Postgres::fmt_value_debug(&<PgValueRef as ValueRef>::to_owned(&value)),
64+
);
65+
} else {
66+
debug_map.entry(&column.name, &format!("decode error: {error:?}"));
67+
}
68+
}
69+
70+
debug_map.finish()
71+
}
72+
}

0 commit comments

Comments
 (0)