diff --git a/Cargo.toml b/Cargo.toml index 0a371eeef..ad5e6467d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ futures-util = { version = "^0.3" } tracing = { version = "0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.5.0", path = "sea-orm-macros", optional = true } -sea-query = { git = "https://github.com/SeaQL/sea-query.git", features = ["thread-safe"] } +sea-query = { git = "https://github.com/SeaQL/sea-query.git", branch = "date-time-local", features = ["thread-safe"] } sea-strum = { version = "^0.23", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true } diff --git a/sea-orm-macros/src/derives/entity_model.rs b/sea-orm-macros/src/derives/entity_model.rs index 9da4f8300..66dae0993 100644 --- a/sea-orm-macros/src/derives/entity_model.rs +++ b/sea-orm-macros/src/derives/entity_model.rs @@ -242,7 +242,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res "DateTime" | "NaiveDateTime" => { quote! { DateTime } } - "DateTimeUtc" | "DateTimeWithTimeZone" => { + "DateTimeUtc" | "DateTimeLocal" | "DateTimeWithTimeZone" => { quote! { TimestampWithTimeZone } } "Uuid" => quote! { Uuid }, diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index b854230ab..749fa5e01 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -612,6 +612,10 @@ impl_into_active_value!(crate::prelude::DateTimeWithTimeZone, Set); #[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] impl_into_active_value!(crate::prelude::DateTimeUtc, Set); +#[cfg(feature = "with-chrono")] +#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))] +impl_into_active_value!(crate::prelude::DateTimeLocal, Set); + #[cfg(feature = "with-rust_decimal")] #[cfg_attr(docsrs, doc(cfg(feature = "with-rust_decimal")))] impl_into_active_value!(crate::prelude::Decimal, Set); diff --git a/src/entity/prelude.rs b/src/entity/prelude.rs index 109b2b4ef..c947d2688 100644 --- a/src/entity/prelude.rs +++ b/src/entity/prelude.rs @@ -72,6 +72,10 @@ pub type DateTimeWithTimeZone = chrono::DateTime; #[cfg(feature = "with-chrono")] pub type DateTimeUtc = chrono::DateTime; +/// Date time with local time zone +#[cfg(feature = "with-chrono")] +pub type DateTimeLocal = chrono::DateTime; + #[cfg(feature = "with-rust_decimal")] pub use rust_decimal::Decimal; diff --git a/src/executor/query.rs b/src/executor/query.rs index cfc7e93fd..e15b3a884 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -272,7 +272,10 @@ try_getable_all!(chrono::NaiveDateTime); try_getable_date_time!(chrono::DateTime); #[cfg(feature = "with-chrono")] -try_getable_date_time!(chrono::DateTime); +try_getable_all!(chrono::DateTime); + +#[cfg(feature = "with-chrono")] +try_getable_all!(chrono::DateTime); #[cfg(feature = "with-rust_decimal")] use rust_decimal::Decimal; @@ -620,6 +623,9 @@ try_from_u64_err!(chrono::DateTime); #[cfg(feature = "with-chrono")] try_from_u64_err!(chrono::DateTime); +#[cfg(feature = "with-chrono")] +try_from_u64_err!(chrono::DateTime); + #[cfg(feature = "with-rust_decimal")] try_from_u64_err!(rust_decimal::Decimal); diff --git a/tests/common/features/mod.rs b/tests/common/features/mod.rs index 8416aa64d..18c0ae78a 100644 --- a/tests/common/features/mod.rs +++ b/tests/common/features/mod.rs @@ -2,9 +2,9 @@ pub mod active_enum; pub mod active_enum_child; pub mod applog; pub mod byte_primary_key; -pub mod datetimeutc; pub mod metadata; pub mod repository; +pub mod satellite; pub mod schema; pub mod sea_orm_active_enums; pub mod self_join; @@ -13,9 +13,9 @@ pub use active_enum::Entity as ActiveEnum; pub use active_enum_child::Entity as ActiveEnumChild; pub use applog::Entity as Applog; pub use byte_primary_key::Entity as BytePrimaryKey; -pub use datetimeutc::Entity as DateTimeUtcTest; pub use metadata::Entity as Metadata; pub use repository::Entity as Repository; +pub use satellite::Entity as Satellite; pub use schema::*; pub use sea_orm_active_enums::*; pub use self_join::Entity as SelfJoin; diff --git a/tests/common/features/datetimeutc.rs b/tests/common/features/satellite.rs similarity index 85% rename from tests/common/features/datetimeutc.rs rename to tests/common/features/satellite.rs index 10e8f19ce..5db48274f 100644 --- a/tests/common/features/datetimeutc.rs +++ b/tests/common/features/satellite.rs @@ -1,7 +1,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] -#[sea_orm(table_name = "satellites")] +#[sea_orm(table_name = "satellite")] pub struct Model { #[sea_orm(primary_key)] pub id: i32, @@ -9,7 +9,7 @@ pub struct Model { #[sea_orm(default_value = "2022-01-26 16:24:00")] pub launch_date: DateTimeUtc, #[sea_orm(default_value = "2022-01-26 16:24:00")] - pub deployment_date: DateTimeUtc, + pub deployment_date: DateTimeLocal, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/tests/common/features/schema.rs b/tests/common/features/schema.rs index 4fae057fd..8fd7b9c8a 100644 --- a/tests/common/features/schema.rs +++ b/tests/common/features/schema.rs @@ -205,32 +205,32 @@ pub async fn create_active_enum_child_table(db: &DbConn) -> Result Result { let stmt = sea_query::Table::create() - .table(datetimeutc::Entity) + .table(satellite::Entity) .col( - ColumnDef::new(datetimeutc::Column::Id) + ColumnDef::new(satellite::Column::Id) .integer() .not_null() .auto_increment() .primary_key(), ) .col( - ColumnDef::new(datetimeutc::Column::SatelliteName) + ColumnDef::new(satellite::Column::SatelliteName) .string() .not_null(), ) .col( - ColumnDef::new(datetimeutc::Column::LaunchDate) + ColumnDef::new(satellite::Column::LaunchDate) .timestamp_with_time_zone() .not_null() .default("2022-01-26 16:24:00"), ) .col( - ColumnDef::new(datetimeutc::Column::DeploymentDate) + ColumnDef::new(satellite::Column::DeploymentDate) .timestamp_with_time_zone() .not_null() .default("2022-01-26 16:24:00"), ) .to_owned(); - create_table(db, &stmt, DateTimeUtcTest).await + create_table(db, &stmt, Satellite).await } diff --git a/tests/timestamp_tests.rs b/tests/timestamp_tests.rs index e5d6fb4a5..d0334a5cb 100644 --- a/tests/timestamp_tests.rs +++ b/tests/timestamp_tests.rs @@ -31,29 +31,26 @@ pub async fn create_applog(db: &DatabaseConnection) -> Result<(), DbErr> { .exec(db) .await?; - assert_eq!(log.id.clone(), res.last_insert_id); + assert_eq!(log.id, res.last_insert_id); assert_eq!(Applog::find().one(db).await?, Some(log.clone())); Ok(()) } pub async fn create_satellites_log(db: &DatabaseConnection) -> Result<(), DbErr> { - let archive = datetimeutc::Model { + let archive = satellite::Model { id: 1, satellite_name: "Sea-00001-2022".to_owned(), launch_date: "2022-01-07T12:11:23Z".parse().unwrap(), deployment_date: "2022-01-07T12:11:23Z".parse().unwrap(), }; - let res = DateTimeUtcTest::insert(archive.clone().into_active_model()) + let res = Satellite::insert(archive.clone().into_active_model()) .exec(db) .await?; - assert_eq!(archive.id.clone(), res.last_insert_id); - assert_eq!( - DateTimeUtcTest::find().one(db).await?, - Some(archive.clone()) - ); + assert_eq!(archive.id, res.last_insert_id); + assert_eq!(Satellite::find().one(db).await?, Some(archive.clone())); Ok(()) }