From a5d7fffc1b6c103161c54b61223008a10ec0a7d7 Mon Sep 17 00:00:00 2001 From: Grzegorz Bartoszek Date: Tue, 23 Apr 2024 00:39:39 +0200 Subject: [PATCH] Add Debug impl for PgRow (#2917) --- sqlx-postgres/src/row.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/sqlx-postgres/src/row.rs b/sqlx-postgres/src/row.rs index 865d8a991..7736fee33 100644 --- a/sqlx-postgres/src/row.rs +++ b/sqlx-postgres/src/row.rs @@ -4,9 +4,11 @@ use crate::message::DataRow; use crate::statement::PgStatementMetadata; use crate::value::PgValueFormat; use crate::{PgColumn, PgValueRef, Postgres}; -use std::sync::Arc; - 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. pub struct PgRow { @@ -48,3 +50,26 @@ impl ColumnIndex for &'_ str { .map(|v| *v) } } + +impl 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(&::to_owned(&value)), + ); + } + Err(error) => { + debug_map.entry(&column.name, &format!("decode error: {error:?}")); + } + } + } + + debug_map.finish() + } +}