Skip to content
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

refactor: lift type mappings into driver crates #2970

Merged
merged 1 commit into from
Mar 30, 2024
Merged

Conversation

abonander
Copy link
Collaborator

@abonander abonander commented Jan 6, 2024

Motivated by #2917

cc @g-bartoszek you can build your changes onto this. Just use Postgres::fmt_value_debug()

@@ -186,7 +192,7 @@ impl_database_ext! {
Vec<sqlx::postgres::types::PgRange<sqlx::types::chrono::DateTime<_>>>,

#[cfg(feature = "chrono")]
&[sqlx::postgres::types::PgRange<sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc>>] |
Vec<sqlx::postgres::types::PgRange<sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc>>> |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is theoretically a breaking change but this only affects code that wouldn't have compiled anyways as &[PgRange<DateTime<Utc>>] doesn't implement Decode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, so because this change requires a type to actually implement Encode or Decode I can't really get around this.

@abonander abonander force-pushed the ab/lift-tyck branch 3 times, most recently from 5d114e4 to 999ae76 Compare January 16, 2024 22:09
@abonander
Copy link
Collaborator Author

While I doubt anyone's actually using the type mappings I had to change (to actually get this to compile), it's still technically a breaking change and will need to wait for the next major release.

On the upside, it's possible to catch mistakes like this in the future because the macro invocation will complain about the lack of a Decode or Encode impl.

/// If `value` is a well-known type, decode and format it using `Debug`.
///
/// If `value` is not a well-known type or could not be decoded, the reason is printed instead.
fn fmt_value_debug(value: &<Self as Database>::Value) -> FmtValue<'_, Self>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the reference to Value be replaced with ValueRef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason why it doesn't is explained at line 59.

It's feasible to add a Clone impl to SqliteValueRef but I would almost prefer to add like a reborrow() method to ValueRef instead, but either of those changes were rather out of scope for this PR.

Since it turned out to be a breaking change anyway, I'd be inclined to revisit that.

@abonander abonander merged commit 02c68a4 into main Mar 30, 2024
62 checks passed
@abonander abonander deleted the ab/lift-tyck branch March 30, 2024 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants