Skip to content

Commit

Permalink
Add Debug impl for PgRow
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bartoszek committed Apr 3, 2024
1 parent 0aae849 commit 2189a2b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions sqlx-postgres/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,3 +50,23 @@ impl ColumnIndex<PgRow> 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() {
if let Ok(value) = self.try_get_raw(index) {
debug_map.entry(
&column.name,
&Postgres::fmt_value_debug(&<PgValueRef as ValueRef>::to_owned(&value)),
);
} else {
debug_map.entry(&column.name, &format!("decode error: {error:?}"));

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Check (tokio, native-tls)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Check (tokio, none)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Check (async-std, none)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Check (async-std, rustls)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Unit Test (tokio, none)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Check (tokio, rustls)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Unit Test (tokio, native-tls)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Unit Test (async-std, native-tls)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / CLI Binaries (ubuntu-latest)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Unit Test (tokio, rustls)

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / CLI Unit Test

cannot find value `error` in this scope

Check failure on line 66 in sqlx-postgres/src/row.rs

View workflow job for this annotation

GitHub Actions / Build SQLx CLI

cannot find value `error` in this scope
}
}

debug_map.finish()
}
}

0 comments on commit 2189a2b

Please sign in to comment.