From 5aa9d500bc6c6c76e104164970151527150b3d5b Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Thu, 15 Aug 2024 22:15:38 -0700 Subject: [PATCH] chore: run `cargo fmt` --- sqlx-postgres/src/arguments.rs | 8 ++++-- sqlx-postgres/src/connection/describe.rs | 31 ++++++++++++------------ sqlx-postgres/src/types/bit_vec.rs | 2 +- sqlx-postgres/src/types/chrono/date.rs | 4 ++- sqlx-postgres/src/types/rust_decimal.rs | 20 +++++++-------- sqlx-postgres/src/types/time/date.rs | 7 +++--- sqlx-postgres/src/types/time/datetime.rs | 7 ++++-- 7 files changed, 43 insertions(+), 36 deletions(-) diff --git a/sqlx-postgres/src/arguments.rs b/sqlx-postgres/src/arguments.rs index 23859fbb79..2e7d5fd9d4 100644 --- a/sqlx-postgres/src/arguments.rs +++ b/sqlx-postgres/src/arguments.rs @@ -274,6 +274,10 @@ impl DerefMut for PgArgumentBuffer { } pub(crate) fn value_size_int4_checked(size: usize) -> Result { - i32::try_from(size) - .map_err(|_| format!("value size would overflow in the binary protocol encoding: {size} > {}", i32::MAX)) + i32::try_from(size).map_err(|_| { + format!( + "value size would overflow in the binary protocol encoding: {size} > {}", + i32::MAX + ) + }) } diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index a579f9217a..e53a054a70 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -2,7 +2,7 @@ use crate::error::Error; use crate::ext::ustr::UStr; use crate::message::{ParameterDescription, RowDescription}; use crate::query_as::query_as; -use crate::query_scalar::{query_scalar}; +use crate::query_scalar::query_scalar; use crate::statement::PgStatementMetadata; use crate::type_info::{PgArrayOf, PgCustomType, PgType, PgTypeKind}; use crate::types::Json; @@ -11,8 +11,8 @@ use crate::HashMap; use crate::{PgColumn, PgConnection, PgTypeInfo}; use futures_core::future::BoxFuture; use smallvec::SmallVec; -use std::sync::Arc; use sqlx_core::query_builder::QueryBuilder; +use std::sync::Arc; /// Describes the type of the `pg_type.typtype` column /// @@ -426,7 +426,7 @@ WHERE rngtypid = $1 if meta.columns.len() * 3 > 65535 { tracing::debug!( ?stmt_id, - num_columns=meta.columns.len(), + num_columns = meta.columns.len(), "number of columns in query is too large to pull nullability for" ); } @@ -436,19 +436,18 @@ WHERE rngtypid = $1 // This will include columns that don't have a `relation_id` (are not from a table); // assuming those are a minority of columns, it's less code to _not_ work around it // and just let Postgres return `NULL`. - let mut nullable_query = QueryBuilder::new( - "SELECT NOT pg_attribute.attnotnull FROM ( " - ); - - nullable_query.push_values( - meta.columns.iter().zip(0i32..), - |mut tuple, (column, i)| { - // ({i}::int4, {column.relation_id}::int4, {column.relation_attribute_no}::int2) - tuple.push_bind(i).push_unseparated("::int4"); - tuple.push_bind(column.relation_id).push_unseparated("::int4"); - tuple.push_bind(column.relation_attribute_no).push_bind_unseparated("::int2"); - }, - ); + let mut nullable_query = QueryBuilder::new("SELECT NOT pg_attribute.attnotnull FROM ( "); + + nullable_query.push_values(meta.columns.iter().zip(0i32..), |mut tuple, (column, i)| { + // ({i}::int4, {column.relation_id}::int4, {column.relation_attribute_no}::int2) + tuple.push_bind(i).push_unseparated("::int4"); + tuple + .push_bind(column.relation_id) + .push_unseparated("::int4"); + tuple + .push_bind(column.relation_attribute_no) + .push_bind_unseparated("::int2"); + }); nullable_query.push( ") as col(idx, table_id, col_idx) \ diff --git a/sqlx-postgres/src/types/bit_vec.rs b/sqlx-postgres/src/types/bit_vec.rs index 299aaf828a..dfc3b16922 100644 --- a/sqlx-postgres/src/types/bit_vec.rs +++ b/sqlx-postgres/src/types/bit_vec.rs @@ -1,3 +1,4 @@ +use crate::arguments::value_size_int4_checked; use crate::{ decode::Decode, encode::{Encode, IsNull}, @@ -8,7 +9,6 @@ use crate::{ use bit_vec::BitVec; use sqlx_core::bytes::Buf; use std::{io, mem}; -use crate::arguments::value_size_int4_checked; impl Type for BitVec { fn type_info() -> PgTypeInfo { diff --git a/sqlx-postgres/src/types/chrono/date.rs b/sqlx-postgres/src/types/chrono/date.rs index 5fc0a8f08d..0327d5c45d 100644 --- a/sqlx-postgres/src/types/chrono/date.rs +++ b/sqlx-postgres/src/types/chrono/date.rs @@ -26,7 +26,9 @@ impl Encode<'_, Postgres> for NaiveDate { let days: i32 = (*self - postgres_epoch_date()) .num_days() .try_into() - .map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres DATE"))?; + .map_err(|_| { + format!("value {self:?} would overflow binary encoding for Postgres DATE") + })?; Encode::::encode(days, buf) } diff --git a/sqlx-postgres/src/types/rust_decimal.rs b/sqlx-postgres/src/types/rust_decimal.rs index d94dfe34cd..83a2d0e08a 100644 --- a/sqlx-postgres/src/types/rust_decimal.rs +++ b/sqlx-postgres/src/types/rust_decimal.rs @@ -193,15 +193,9 @@ mod tests { fn zero() { let zero: Decimal = "0".parse().unwrap(); - assert_eq!( - PgNumeric::from(&zero), - PgNumeric::ZERO, - ); + assert_eq!(PgNumeric::from(&zero), PgNumeric::ZERO,); - assert_eq!( - Decimal::try_from(&PgNumeric::ZERO).unwrap(), - Decimal::ZERO - ); + assert_eq!(Decimal::try_from(&PgNumeric::ZERO).unwrap(), Decimal::ZERO); } #[test] @@ -384,7 +378,10 @@ mod tests { let actual_decimal = Decimal::try_from(expected_numeric).unwrap(); assert_eq!(actual_decimal, Decimal::MAX); // Value split by 10,000's to match the expected digits[] - assert_eq!(actual_decimal.mantissa(), 7_9228_1625_1426_4337_5935_4395_0335); + assert_eq!( + actual_decimal.mantissa(), + 7_9228_1625_1426_4337_5935_4395_0335 + ); assert_eq!(actual_decimal.scale(), 0); } @@ -406,7 +403,10 @@ mod tests { let actual_decimal = Decimal::try_from(expected_numeric).unwrap(); assert_eq!(actual_decimal, max_value_max_scale); - assert_eq!(actual_decimal.mantissa(), 79_228_162_514_264_337_593_543_950_335); + assert_eq!( + actual_decimal.mantissa(), + 79_228_162_514_264_337_593_543_950_335 + ); assert_eq!(actual_decimal.scale(), 28); } diff --git a/sqlx-postgres/src/types/time/date.rs b/sqlx-postgres/src/types/time/date.rs index 619537c5af..2afa57ee0d 100644 --- a/sqlx-postgres/src/types/time/date.rs +++ b/sqlx-postgres/src/types/time/date.rs @@ -23,10 +23,9 @@ impl PgHasArrayType for Date { impl Encode<'_, Postgres> for Date { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result { // DATE is encoded as number of days since epoch (2000-01-01) - let days: i32 = (*self - PG_EPOCH) - .whole_days() - .try_into() - .map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres DATE"))?; + let days: i32 = (*self - PG_EPOCH).whole_days().try_into().map_err(|_| { + format!("value {self:?} would overflow binary encoding for Postgres DATE") + })?; Encode::::encode(days, buf) } diff --git a/sqlx-postgres/src/types/time/datetime.rs b/sqlx-postgres/src/types/time/datetime.rs index d51002286d..3484116bd1 100644 --- a/sqlx-postgres/src/types/time/datetime.rs +++ b/sqlx-postgres/src/types/time/datetime.rs @@ -37,9 +37,12 @@ impl PgHasArrayType for OffsetDateTime { impl Encode<'_, Postgres> for PrimitiveDateTime { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result { // TIMESTAMP is encoded as the microseconds since the epoch - let micros: i64 = (*self - PG_EPOCH.midnight()).whole_microseconds() + let micros: i64 = (*self - PG_EPOCH.midnight()) + .whole_microseconds() .try_into() - .map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres TIME"))?; + .map_err(|_| { + format!("value {self:?} would overflow binary encoding for Postgres TIME") + })?; Encode::::encode(micros, buf) }