Skip to content

[Breaking Change] Unify Debug implementations across PgRow, MySqlRow and SqliteRow #3890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

davidcornu
Copy link

@davidcornu davidcornu commented Jun 6, 2025

Context

In a personal code base I currently maintain a Row implementation called DebugRow as a catch-all type for queries so that I can use its Debug implementation for snapshot testing (using the great insta crate).

While upgrading the version of sqlx I noticed there was now a useful Debug implementation for PgRow (#2917) which had me hoping there was an equivalent for SqliteRow, but after digging through the code I found out

  • PgRow has a custom Debug which prints out the contents of the row using debug_map()
  • MySqlRow uses a derived Debug
  • SqliteRow does not implement Debug

Rather than implement similar logic to PgRow for SqliteRow I figured it might be better to unify the implementations as the various traits (e.g. Row, Database, TypeChecking) provide everything needed to implement PgRow's version generically.

Also related: #150

Proposed changes

  1. Introduce a new sqlx_core::row::debug_row function
  2. Use (1) to implement Debug on SqliteRow
  3. Use (1) to replace PgRow's Debug implementation
  4. Use (1) to replace MySqlRow's derived Debug

Is this a breaking change?

Yes.

  1. PgRow's Debug implementation changes a little bit because of the use of std::any::type_name
    (This could be avoided by passing a name to debug_row instead but is definitely less elegant)
  2. MySqlRow's Debug implementation would be completely different

If this is too ambitious of a change I'm happy to pare it down to just the SqliteRow change as that's fundamentally what I'm after.

@@ -176,3 +177,32 @@ pub trait Row: Unpin + Send + Sync + 'static {
where
I: ColumnIndex<Self>;
}

pub fn debug_row<R>(row: &R, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this being pub but given that it's defined in the core crate and used in the database crates I don't think there's a better way.

Happy to either add docs or a #[doc(hidden)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant