Support chrono::NaiveDate

This commit is contained in:
Billy Chan 2021-09-27 18:35:42 +08:00
parent beb3ec62dc
commit f7e96b3d72
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7
7 changed files with 13 additions and 1 deletions

View File

@ -170,7 +170,7 @@ 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 },
"Date" | "NaiveDate" => quote! { Date },
"NaiveTime" => quote! { Time },
"DateTime" | "NaiveDateTime" => {
quote! { DateTime }

View File

@ -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;

View File

@ -241,6 +241,9 @@ 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::NaiveDateTime);

View File

@ -8,6 +8,7 @@ pub struct Model {
pub key: String,
pub value: String,
pub bytes: Vec<u8>,
pub date: Date,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -286,6 +286,7 @@ 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())
.to_owned();
create_table(db, &stmt, Metadata).await

View File

@ -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),
},
];

View File

@ -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())