fix: audit sqlx_postgres::types::chrono
for overflowing casts
This commit is contained in:
parent
112b4a84b5
commit
8360d48296
1 changed files with 5 additions and 1 deletions
|
@ -23,7 +23,11 @@ impl PgHasArrayType for NaiveDate {
|
|||
impl Encode<'_, Postgres> for NaiveDate {
|
||||
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result<IsNull, BoxDynError> {
|
||||
// DATE is encoded as the days since epoch
|
||||
let days = (*self - postgres_epoch_date()).num_days() as i32;
|
||||
let days: i32 = (*self - postgres_epoch_date())
|
||||
.num_days()
|
||||
.try_into()
|
||||
.map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres DATE"))?;
|
||||
|
||||
Encode::<Postgres>::encode(days, buf)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue