From 768b2cf5520bd3eb30b4edd2338877f23bf7c0d3 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 28 Jul 2024 03:04:20 +0200 Subject: [PATCH] fixed deprecation warnings (#3384) --- tests/postgres/types.rs | 34 ++++++++++++++++------------------ tests/sqlite/types.rs | 6 +++--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 5d758104e6..4912339dc2 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -260,51 +260,49 @@ mod chrono { type PgTimeTz = sqlx::postgres::types::PgTimeTz; test_type!(chrono_date(Postgres, - "DATE '2001-01-05'" == NaiveDate::from_ymd(2001, 1, 5), - "DATE '2050-11-23'" == NaiveDate::from_ymd(2050, 11, 23) + "DATE '2001-01-05'" == NaiveDate::from_ymd_opt(2001, 1, 5).unwrap(), + "DATE '2050-11-23'" == NaiveDate::from_ymd_opt(2050, 11, 23).unwrap() )); test_type!(chrono_time(Postgres, - "TIME '05:10:20.115100'" == NaiveTime::from_hms_micro(5, 10, 20, 115100) + "TIME '05:10:20.115100'" == NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap() )); test_type!(chrono_date_time(Postgres, - "'2019-01-02 05:10:20'::timestamp" == NaiveDate::from_ymd(2019, 1, 2).and_hms(5, 10, 20) + "'2019-01-02 05:10:20'::timestamp" == NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_opt(5, 10, 20).unwrap() )); test_type!(chrono_date_time_vec>(Postgres, "array['2019-01-02 05:10:20']::timestamp[]" - == vec![NaiveDate::from_ymd(2019, 1, 2).and_hms(5, 10, 20)] + == vec![NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_opt(5, 10, 20).unwrap()] )); test_type!(chrono_date_time_tz_utc>(Postgres, "TIMESTAMPTZ '2019-01-02 05:10:20.115100'" - == DateTime::::from_utc( - NaiveDate::from_ymd(2019, 1, 2).and_hms_micro(5, 10, 20, 115100), - Utc, + == Utc.from_utc_datetime( + &NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_micro_opt(5, 10, 20, 115100).unwrap(), ) )); test_type!(chrono_date_time_tz>(Postgres, "TIMESTAMPTZ '2019-01-02 05:10:20.115100+06:30'" - == FixedOffset::east(60 * 60 * 6 + 1800).ymd(2019, 1, 2).and_hms_micro(5, 10, 20, 115100) + == FixedOffset::east_opt(60 * 60 * 6 + 1800).unwrap().ymd(2019, 1, 2).and_hms_micro_opt(5, 10, 20, 115100).unwrap() )); test_type!(chrono_date_time_tz_vec>>(Postgres, "array['2019-01-02 05:10:20.115100']::timestamptz[]" == vec![ - DateTime::::from_utc( - NaiveDate::from_ymd(2019, 1, 2).and_hms_micro(5, 10, 20, 115100), - Utc, + Utc.from_utc_datetime( + &NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_micro_opt(5, 10, 20, 115100).unwrap(), ) ] )); test_type!(chrono_time_tz(Postgres, - "TIMETZ '05:10:20.115100+00'" == PgTimeTz { time: NaiveTime::from_hms_micro(5, 10, 20, 115100), offset: FixedOffset::east(0) }, - "TIMETZ '05:10:20.115100+06:30'" == PgTimeTz { time: NaiveTime::from_hms_micro(5, 10, 20, 115100), offset: FixedOffset::east(60 * 60 * 6 + 1800) }, - "TIMETZ '05:10:20.115100-05'" == PgTimeTz { time: NaiveTime::from_hms_micro(5, 10, 20, 115100), offset: FixedOffset::west(60 * 60 * 5) }, - "TIMETZ '05:10:20+02'" == PgTimeTz { time: NaiveTime::from_hms(5, 10, 20), offset: FixedOffset::east(60 * 60 * 2 )} + "TIMETZ '05:10:20.115100+00'" == PgTimeTz { time: NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap(), offset: FixedOffset::east_opt(0).unwrap() }, + "TIMETZ '05:10:20.115100+06:30'" == PgTimeTz { time: NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap(), offset: FixedOffset::east_opt(60 * 60 * 6 + 1800).unwrap() }, + "TIMETZ '05:10:20.115100-05'" == PgTimeTz { time: NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap(), offset: FixedOffset::west_opt(60 * 60 * 5).unwrap() }, + "TIMETZ '05:10:20+02'" == PgTimeTz { time: NaiveTime::from_hms_opt(5, 10, 20).unwrap(), offset: FixedOffset::east_opt(60 * 60 * 2 ).unwrap() } )); } @@ -586,7 +584,7 @@ test_prepared_type!(citext_array>(Postgres, #[cfg(any(postgres_14, postgres_15))] test_type!(ltree(Postgres, "'Foo.Bar.Baz.Quux'::ltree" == sqlx::postgres::types::PgLTree::from_str("Foo.Bar.Baz.Quux").unwrap(), - "'Alpha.Beta.Delta.Gamma'::ltree" == sqlx::postgres::types::PgLTree::from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap(), + "'Alpha.Beta.Delta.Gamma'::ltree" == sqlx::postgres::types::PgLTree::try_from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap(), )); // FIXME: needed to disable `ltree` tests in version that don't have a binary format for it @@ -596,7 +594,7 @@ test_type!(ltree_vec>(Postgres, "array['Foo.Bar.Baz.Quux', 'Alpha.Beta.Delta.Gamma']::ltree[]" == vec![ sqlx::postgres::types::PgLTree::from_str("Foo.Bar.Baz.Quux").unwrap(), - sqlx::postgres::types::PgLTree::from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap() + sqlx::postgres::types::PgLTree::try_from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap() ] )); diff --git a/tests/sqlite/types.rs b/tests/sqlite/types.rs index 71c788d43c..2497e406cc 100644 --- a/tests/sqlite/types.rs +++ b/tests/sqlite/types.rs @@ -100,15 +100,15 @@ mod chrono { use sqlx::types::chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, TimeZone, Utc}; test_type!(chrono_naive_date_time(Sqlite, "SELECT datetime({0}) is datetime(?), {0}, ?", - "'2019-01-02 05:10:20'" == NaiveDate::from_ymd(2019, 1, 2).and_hms(5, 10, 20) + "'2019-01-02 05:10:20'" == NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_opt(5, 10, 20).unwrap() )); test_type!(chrono_date_time_utc>(Sqlite, "SELECT datetime({0}) is datetime(?), {0}, ?", - "'1996-12-20T00:39:57+00:00'" == Utc.ymd(1996, 12, 20).and_hms(0, 39, 57) + "'1996-12-20T00:39:57+00:00'" == Utc.with_ymd_and_hms(1996, 12, 20, 0, 39, 57).unwrap() )); test_type!(chrono_date_time_fixed_offset>(Sqlite, "SELECT datetime({0}) is datetime(?), {0}, ?", - "'2016-11-08T03:50:23-05:00'" == DateTime::::from(FixedOffset::west(5 * 3600).ymd(2016, 11, 08).and_hms(3, 50, 23)) + "'2016-11-08T03:50:23-05:00'" == DateTime::::from(FixedOffset::west_opt(5 * 3600).unwrap().with_ymd_and_hms(2016, 11, 08, 3, 50, 23).unwrap()) )); }