From f7e96b3d72dfff2d9764c97715d7c845f43e6515 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 27 Sep 2021 18:35:42 +0800 Subject: [PATCH 1/5] Support `chrono::NaiveDate` --- 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 f0772763..ea9d05f5 100644 --- a/sea-orm-macros/src/derives/entity_model.rs +++ b/sea-orm-macros/src/derives/entity_model.rs @@ -170,7 +170,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res "f32" => quote! { Float }, "f64" => quote! { Double }, "bool" => quote! { Boolean }, - "NaiveDate" => quote! { Date }, + "Date" | "NaiveDate" => quote! { Date }, "NaiveTime" => quote! { Time }, "DateTime" | "NaiveDateTime" => { quote! { DateTime } diff --git a/src/entity/prelude.rs b/src/entity/prelude.rs index 8d87a4b2..221736f7 100644 --- a/src/entity/prelude.rs +++ b/src/entity/prelude.rs @@ -9,6 +9,9 @@ pub use crate::{ #[cfg(feature = "with-json")] pub use serde_json::Value as Json; +#[cfg(feature = "with-chrono")] +pub use chrono::NaiveDate as Date; + #[cfg(feature = "with-chrono")] pub use chrono::NaiveDateTime as DateTime; diff --git a/src/executor/query.rs b/src/executor/query.rs index ae09f97c..483d7d54 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -241,6 +241,9 @@ try_getable_all!(Vec); #[cfg(feature = "with-json")] try_getable_all!(serde_json::Value); +#[cfg(feature = "with-chrono")] +try_getable_all!(chrono::NaiveDate); + #[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 95a7a48b..c7727fb8 100644 --- a/tests/common/bakery_chain/metadata.rs +++ b/tests/common/bakery_chain/metadata.rs @@ -8,6 +8,7 @@ pub struct Model { pub key: String, pub value: String, pub bytes: Vec, + pub date: Date, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/tests/common/setup/schema.rs b/tests/common/setup/schema.rs index 64f31dfe..0787e971 100644 --- a/tests/common/setup/schema.rs +++ b/tests/common/setup/schema.rs @@ -286,6 +286,7 @@ pub async fn create_metadata_table(db: &DbConn) -> Result { .col(ColumnDef::new(metadata::Column::Key).string().not_null()) .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()) .to_owned(); create_table(db, &stmt, Metadata).await diff --git a/tests/parallel_tests.rs b/tests/parallel_tests.rs index 0ac09fd6..d83c7ab5 100644 --- a/tests/parallel_tests.rs +++ b/tests/parallel_tests.rs @@ -25,18 +25,21 @@ pub async fn crud_in_parallel(db: &DatabaseConnection) -> Result<(), DbErr> { key: "markup".to_owned(), value: "1.18".to_owned(), bytes: vec![1, 2, 3], + date: Date::from_ymd(2021, 9, 27), }, metadata::Model { uuid: Uuid::new_v4(), key: "exchange_rate".to_owned(), value: "0.78".to_owned(), bytes: vec![1, 2, 3], + date: Date::from_ymd(2021, 9, 27), }, metadata::Model { uuid: Uuid::new_v4(), key: "service_charge".to_owned(), value: "1.1".to_owned(), bytes: vec![1, 2, 3], + date: Date::from_ymd(2021, 9, 27), }, ]; diff --git a/tests/uuid_tests.rs b/tests/uuid_tests.rs index e58daca4..c6edd2aa 100644 --- a/tests/uuid_tests.rs +++ b/tests/uuid_tests.rs @@ -23,6 +23,7 @@ pub async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> { key: "markup".to_owned(), value: "1.18".to_owned(), bytes: vec![1, 2, 3], + date: Date::from_ymd(2021, 9, 27), }; let res = Metadata::insert(metadata.clone().into_active_model()) From 02066cef6ed1e071b5181fec81cf0f8a062e1216 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 28 Sep 2021 11:40:40 +0800 Subject: [PATCH 2/5] 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()) From d9f63e8d170788db585f5eb44983ea2bf52134ef Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 28 Sep 2021 18:01:18 +0800 Subject: [PATCH 3/5] Fixup --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 37aa1b6e..753e59d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ sea-query = { version = "^0.16.3", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true } -sqlx = { version = "^0.5", optional = true } +sqlx = { version = "^0.5", git = "https://github.com/billy1624/sqlx.git", branch = "fix-sqlite-naive-time", optional = true } uuid = { version = "0.8", features = ["serde", "v4"], optional = true } [dev-dependencies] From 05b370434b3765c1a1c695d8e8e951845f5a0236 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 30 Sep 2021 10:45:59 +0800 Subject: [PATCH 4/5] Without fixing SQLx source code --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 753e59d5..39003c5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,11 +30,11 @@ futures-util = { version = "^0.3" } log = { version = "^0.4", optional = true } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.2.3", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.16.3", features = ["thread-safe"] } +sea-query = { version = "^0.16.4", git = "https://github.com/SeaQL/sea-query.git", branch = "sqlite-time-temp-fixup", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true } -sqlx = { version = "^0.5", git = "https://github.com/billy1624/sqlx.git", branch = "fix-sqlite-naive-time", optional = true } +sqlx = { version = "^0.5", optional = true } uuid = { version = "0.8", features = ["serde", "v4"], optional = true } [dev-dependencies] From cb5445b035fe121c70edc44ad5d0b07f96b20ff6 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Thu, 30 Sep 2021 22:42:31 +0800 Subject: [PATCH 5/5] Bump sea-query to 0.16.5 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 39003c5f..d1ddf12e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ futures-util = { version = "^0.3" } log = { version = "^0.4", optional = true } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.2.3", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.16.4", git = "https://github.com/SeaQL/sea-query.git", branch = "sqlite-time-temp-fixup", features = ["thread-safe"] } +sea-query = { version = "^0.16.5", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true }