From 02066cef6ed1e071b5181fec81cf0f8a062e1216 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 28 Sep 2021 11:40:40 +0800 Subject: [PATCH] Support `chrono::NaiveTime` --- sea-orm-macros/src/derives/entity_model.rs | 2 +- src/entity/prelude.rs | 3 +++ src/executor/query.rs | 3 +++ tests/common/bakery_chain/metadata.rs | 1 + tests/common/setup/schema.rs | 1 + tests/parallel_tests.rs | 3 +++ tests/uuid_tests.rs | 1 + 7 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sea-orm-macros/src/derives/entity_model.rs b/sea-orm-macros/src/derives/entity_model.rs index ea9d05f5..ba448bd4 100644 --- a/sea-orm-macros/src/derives/entity_model.rs +++ b/sea-orm-macros/src/derives/entity_model.rs @@ -171,7 +171,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res "f64" => quote! { Double }, "bool" => quote! { Boolean }, "Date" | "NaiveDate" => quote! { Date }, - "NaiveTime" => quote! { Time }, + "Time" | "NaiveTime" => quote! { Time }, "DateTime" | "NaiveDateTime" => { quote! { DateTime } } diff --git a/src/entity/prelude.rs b/src/entity/prelude.rs index 221736f7..fb89a454 100644 --- a/src/entity/prelude.rs +++ b/src/entity/prelude.rs @@ -12,6 +12,9 @@ pub use serde_json::Value as Json; #[cfg(feature = "with-chrono")] pub use chrono::NaiveDate as Date; +#[cfg(feature = "with-chrono")] +pub use chrono::NaiveTime as Time; + #[cfg(feature = "with-chrono")] pub use chrono::NaiveDateTime as DateTime; diff --git a/src/executor/query.rs b/src/executor/query.rs index 483d7d54..9fda50ff 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -244,6 +244,9 @@ try_getable_all!(serde_json::Value); #[cfg(feature = "with-chrono")] try_getable_all!(chrono::NaiveDate); +#[cfg(feature = "with-chrono")] +try_getable_all!(chrono::NaiveTime); + #[cfg(feature = "with-chrono")] try_getable_all!(chrono::NaiveDateTime); diff --git a/tests/common/bakery_chain/metadata.rs b/tests/common/bakery_chain/metadata.rs index c7727fb8..9130bbbd 100644 --- a/tests/common/bakery_chain/metadata.rs +++ b/tests/common/bakery_chain/metadata.rs @@ -9,6 +9,7 @@ pub struct Model { pub value: String, pub bytes: Vec, pub date: Date, + pub time: Time, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/tests/common/setup/schema.rs b/tests/common/setup/schema.rs index 0787e971..74e3d390 100644 --- a/tests/common/setup/schema.rs +++ b/tests/common/setup/schema.rs @@ -287,6 +287,7 @@ pub async fn create_metadata_table(db: &DbConn) -> Result { .col(ColumnDef::new(metadata::Column::Value).string().not_null()) .col(ColumnDef::new(metadata::Column::Bytes).binary().not_null()) .col(ColumnDef::new(metadata::Column::Date).date().not_null()) + .col(ColumnDef::new(metadata::Column::Time).time().not_null()) .to_owned(); create_table(db, &stmt, Metadata).await diff --git a/tests/parallel_tests.rs b/tests/parallel_tests.rs index d83c7ab5..6e18cb52 100644 --- a/tests/parallel_tests.rs +++ b/tests/parallel_tests.rs @@ -26,6 +26,7 @@ pub async fn crud_in_parallel(db: &DatabaseConnection) -> Result<(), DbErr> { value: "1.18".to_owned(), bytes: vec![1, 2, 3], date: Date::from_ymd(2021, 9, 27), + time: Time::from_hms(11, 32, 55), }, metadata::Model { uuid: Uuid::new_v4(), @@ -33,6 +34,7 @@ pub async fn crud_in_parallel(db: &DatabaseConnection) -> Result<(), DbErr> { value: "0.78".to_owned(), bytes: vec![1, 2, 3], date: Date::from_ymd(2021, 9, 27), + time: Time::from_hms(11, 32, 55), }, metadata::Model { uuid: Uuid::new_v4(), @@ -40,6 +42,7 @@ pub async fn crud_in_parallel(db: &DatabaseConnection) -> Result<(), DbErr> { value: "1.1".to_owned(), bytes: vec![1, 2, 3], date: Date::from_ymd(2021, 9, 27), + time: Time::from_hms(11, 32, 55), }, ]; diff --git a/tests/uuid_tests.rs b/tests/uuid_tests.rs index c6edd2aa..bf13f689 100644 --- a/tests/uuid_tests.rs +++ b/tests/uuid_tests.rs @@ -24,6 +24,7 @@ pub async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> { value: "1.18".to_owned(), bytes: vec![1, 2, 3], date: Date::from_ymd(2021, 9, 27), + time: Time::from_hms(11, 32, 55), }; let res = Metadata::insert(metadata.clone().into_active_model())