Support chrono::NaiveDate
This commit is contained in:
parent
beb3ec62dc
commit
f7e96b3d72
@ -170,7 +170,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
|||||||
"f32" => quote! { Float },
|
"f32" => quote! { Float },
|
||||||
"f64" => quote! { Double },
|
"f64" => quote! { Double },
|
||||||
"bool" => quote! { Boolean },
|
"bool" => quote! { Boolean },
|
||||||
"NaiveDate" => quote! { Date },
|
"Date" | "NaiveDate" => quote! { Date },
|
||||||
"NaiveTime" => quote! { Time },
|
"NaiveTime" => quote! { Time },
|
||||||
"DateTime" | "NaiveDateTime" => {
|
"DateTime" | "NaiveDateTime" => {
|
||||||
quote! { DateTime }
|
quote! { DateTime }
|
||||||
|
@ -9,6 +9,9 @@ pub use crate::{
|
|||||||
#[cfg(feature = "with-json")]
|
#[cfg(feature = "with-json")]
|
||||||
pub use serde_json::Value as Json;
|
pub use serde_json::Value as Json;
|
||||||
|
|
||||||
|
#[cfg(feature = "with-chrono")]
|
||||||
|
pub use chrono::NaiveDate as Date;
|
||||||
|
|
||||||
#[cfg(feature = "with-chrono")]
|
#[cfg(feature = "with-chrono")]
|
||||||
pub use chrono::NaiveDateTime as DateTime;
|
pub use chrono::NaiveDateTime as DateTime;
|
||||||
|
|
||||||
|
@ -241,6 +241,9 @@ try_getable_all!(Vec<u8>);
|
|||||||
#[cfg(feature = "with-json")]
|
#[cfg(feature = "with-json")]
|
||||||
try_getable_all!(serde_json::Value);
|
try_getable_all!(serde_json::Value);
|
||||||
|
|
||||||
|
#[cfg(feature = "with-chrono")]
|
||||||
|
try_getable_all!(chrono::NaiveDate);
|
||||||
|
|
||||||
#[cfg(feature = "with-chrono")]
|
#[cfg(feature = "with-chrono")]
|
||||||
try_getable_all!(chrono::NaiveDateTime);
|
try_getable_all!(chrono::NaiveDateTime);
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ pub struct Model {
|
|||||||
pub key: String,
|
pub key: String,
|
||||||
pub value: String,
|
pub value: String,
|
||||||
pub bytes: Vec<u8>,
|
pub bytes: Vec<u8>,
|
||||||
|
pub date: Date,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
@ -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::Key).string().not_null())
|
||||||
.col(ColumnDef::new(metadata::Column::Value).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::Bytes).binary().not_null())
|
||||||
|
.col(ColumnDef::new(metadata::Column::Date).date().not_null())
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
create_table(db, &stmt, Metadata).await
|
create_table(db, &stmt, Metadata).await
|
||||||
|
@ -25,18 +25,21 @@ pub async fn crud_in_parallel(db: &DatabaseConnection) -> Result<(), DbErr> {
|
|||||||
key: "markup".to_owned(),
|
key: "markup".to_owned(),
|
||||||
value: "1.18".to_owned(),
|
value: "1.18".to_owned(),
|
||||||
bytes: vec![1, 2, 3],
|
bytes: vec![1, 2, 3],
|
||||||
|
date: Date::from_ymd(2021, 9, 27),
|
||||||
},
|
},
|
||||||
metadata::Model {
|
metadata::Model {
|
||||||
uuid: Uuid::new_v4(),
|
uuid: Uuid::new_v4(),
|
||||||
key: "exchange_rate".to_owned(),
|
key: "exchange_rate".to_owned(),
|
||||||
value: "0.78".to_owned(),
|
value: "0.78".to_owned(),
|
||||||
bytes: vec![1, 2, 3],
|
bytes: vec![1, 2, 3],
|
||||||
|
date: Date::from_ymd(2021, 9, 27),
|
||||||
},
|
},
|
||||||
metadata::Model {
|
metadata::Model {
|
||||||
uuid: Uuid::new_v4(),
|
uuid: Uuid::new_v4(),
|
||||||
key: "service_charge".to_owned(),
|
key: "service_charge".to_owned(),
|
||||||
value: "1.1".to_owned(),
|
value: "1.1".to_owned(),
|
||||||
bytes: vec![1, 2, 3],
|
bytes: vec![1, 2, 3],
|
||||||
|
date: Date::from_ymd(2021, 9, 27),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ pub async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> {
|
|||||||
key: "markup".to_owned(),
|
key: "markup".to_owned(),
|
||||||
value: "1.18".to_owned(),
|
value: "1.18".to_owned(),
|
||||||
bytes: vec![1, 2, 3],
|
bytes: vec![1, 2, 3],
|
||||||
|
date: Date::from_ymd(2021, 9, 27),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = Metadata::insert(metadata.clone().into_active_model())
|
let res = Metadata::insert(metadata.clone().into_active_model())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user