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 },
|
||||
"f64" => quote! { Double },
|
||||
"bool" => quote! { Boolean },
|
||||
"NaiveDate" => quote! { Date },
|
||||
"Date" | "NaiveDate" => quote! { Date },
|
||||
"NaiveTime" => quote! { Time },
|
||||
"DateTime" | "NaiveDateTime" => {
|
||||
quote! { DateTime }
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user