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

Fix for Issue #2549 - cannot use feature "rust_decimal" without also using "bigdecimal" #2585

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sqlx-macros-core/src/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl_database_ext! {
#[cfg(feature = "bigdecimal")]
sqlx::types::BigDecimal,

#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
sqlx::types::Decimal,

#[cfg(feature = "ipnetwork")]
Expand Down Expand Up @@ -118,7 +118,7 @@ impl_database_ext! {
#[cfg(feature = "bigdecimal")]
Vec<sqlx::types::BigDecimal> | &[sqlx::types::BigDecimal],

#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
Vec<sqlx::types::Decimal> | &[sqlx::types::Decimal],

#[cfg(feature = "ipnetwork")]
Expand All @@ -138,7 +138,7 @@ impl_database_ext! {
#[cfg(feature = "bigdecimal")]
sqlx::postgres::types::PgRange<sqlx::types::BigDecimal>,

#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
sqlx::postgres::types::PgRange<sqlx::types::Decimal>,

#[cfg(feature = "chrono")]
Expand Down
2 changes: 1 addition & 1 deletion sqlx-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ migrate = ["sqlx-core/migrate"]
offline = ["sqlx-core/offline"]

# Type integration features which require additional dependencies
rust_decimal = ["dep:rust_decimal"]
rust_decimal = ["dep:rust_decimal", "dep:num-bigint"]
bigdecimal = ["dep:bigdecimal", "dep:num-bigint"]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion sqlx-postgres/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod time_tz;
#[cfg(feature = "bigdecimal")]
mod bigdecimal;

#[cfg(any(feature = "bigdecimal", feature = "decimal"))]
#[cfg(any(feature = "bigdecimal", feature = "rust_decimal"))]
mod numeric;

#[cfg(feature = "rust_decimal")]
Expand Down
8 changes: 4 additions & 4 deletions sqlx-postgres/src/types/money.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl PgMoney {
/// See the type-level docs for an explanation of `locale_frac_digits`.
///
/// [`Decimal`]: crate::types::Decimal
#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
pub fn to_decimal(self, locale_frac_digits: u32) -> rust_decimal::Decimal {
rust_decimal::Decimal::new(self.0, locale_frac_digits)
}
Expand All @@ -94,7 +94,7 @@ impl PgMoney {
/// If the value is larger than 63 bits it will be truncated.
///
/// [`Decimal`]: crate::types::Decimal
#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
pub fn from_decimal(mut decimal: rust_decimal::Decimal, locale_frac_digits: u32) -> Self {
// this is all we need to convert to our expected locale's `frac_digits`
decimal.rescale(locale_frac_digits);
Expand Down Expand Up @@ -316,7 +316,7 @@ mod tests {
}

#[test]
#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
fn conversion_to_decimal_works() {
assert_eq!(
rust_decimal::Decimal::new(12345, 2),
Expand All @@ -325,7 +325,7 @@ mod tests {
}

#[test]
#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
fn conversion_from_decimal_works() {
assert_eq!(
PgMoney(12345),
Expand Down
2 changes: 1 addition & 1 deletion sqlx-postgres/src/types/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Type<Postgres> for PgRange<bigdecimal::BigDecimal> {
}
}

#[cfg(feature = "decimal")]
#[cfg(feature = "rust_decimal")]
impl Type<Postgres> for PgRange<rust_decimal::Decimal> {
fn type_info() -> PgTypeInfo {
PgTypeInfo::NUM_RANGE
Expand Down