Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support chrono::NaiveDate & chrono::NaiveTime #207

Merged
merged 5 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3", 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 }
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
"f32" => quote! { Float },
"f64" => quote! { Double },
"bool" => quote! { Boolean },
"NaiveDate" => quote! { Date },
"NaiveTime" => quote! { Time },
"Date" | "NaiveDate" => quote! { Date },
"Time" | "NaiveTime" => quote! { Time },
"DateTime" | "NaiveDateTime" => {
quote! { DateTime }
}
Expand Down
6 changes: 6 additions & 0 deletions src/entity/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ 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::NaiveTime as Time;

#[cfg(feature = "with-chrono")]
pub use chrono::NaiveDateTime as DateTime;

Expand Down
6 changes: 6 additions & 0 deletions src/executor/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ try_getable_all!(Vec<u8>);
#[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::NaiveTime);

#[cfg(feature = "with-chrono")]
try_getable_all!(chrono::NaiveDateTime);

Expand Down
2 changes: 2 additions & 0 deletions tests/common/bakery_chain/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct Model {
pub key: String,
pub value: String,
pub bytes: Vec<u8>,
pub date: Date,
pub time: Time,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 2 additions & 0 deletions tests/common/setup/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ pub async fn create_metadata_table(db: &DbConn) -> Result<ExecResult, DbErr> {
.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())
.col(ColumnDef::new(metadata::Column::Time).time().not_null())
.to_owned();

create_table(db, &stmt, Metadata).await
Expand Down
6 changes: 6 additions & 0 deletions tests/parallel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ 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),
time: Time::from_hms(11, 32, 55),
},
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),
time: Time::from_hms(11, 32, 55),
},
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),
time: Time::from_hms(11, 32, 55),
},
];

Expand Down
2 changes: 2 additions & 0 deletions tests/uuid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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),
time: Time::from_hms(11, 32, 55),
};

let res = Metadata::insert(metadata.clone().into_active_model())
Expand Down