This commit is contained in:
JMARyA 2024-07-18 14:10:29 +02:00
parent 97348a9275
commit 0d23326aa2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 26 additions and 7 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
/mongod_derive/target

View file

@ -96,7 +96,7 @@ pub fn model_derive(input: TokenStream) -> TokenStream {
async fn update_values(
&mut self,
obj: &serde_json::Map<String, serde_json::Value>,
update: &mut mongodb::bson::Document,
update: &mut mongod::mongodb::bson::Document,
) {
#( #field_process_code )*
}

View file

@ -19,7 +19,10 @@ macro_rules! update_historic_str {
if !(&field.current == val_str) {
field.update(val_str.to_owned());
$entity.$field = field;
$update.insert($key, mongodb::bson::to_bson(&$entity.$field).unwrap());
$update.insert(
$key,
mongod::mongodb::bson::to_bson(&$entity.$field).unwrap(),
);
}
}
}
@ -46,7 +49,10 @@ macro_rules! update_historic_ref_option {
let value = Historic::new(Reference::new_raw(val_str).await.unwrap());
let field = $entity.$field.clone().unwrap_or_else(|| value);
$entity.$field = Some(field);
$update.insert($key, mongodb::bson::to_bson(&$entity.$field).unwrap());
$update.insert(
$key,
mongod::mongodb::bson::to_bson(&$entity.$field).unwrap(),
);
}
}
};
@ -76,7 +82,10 @@ macro_rules! update_historic_vec {
.collect(),
);
$entity.$field = field;
$update.insert($key, mongodb::bson::to_bson(&$entity.$field).unwrap());
$update.insert(
$key,
mongod::mongodb::bson::to_bson(&$entity.$field).unwrap(),
);
}
}
};
@ -102,7 +111,10 @@ macro_rules! update_value {
if let Ok(val) = serde_json::from_value::<$t>(val.clone()) {
if val != $entity.$field {
$entity.$field = val;
$update.insert($key, mongodb::bson::to_bson(&$entity.$field).unwrap());
$update.insert(
$key,
mongod::mongodb::bson::to_bson(&$entity.$field).unwrap(),
);
}
}
}
@ -130,11 +142,17 @@ macro_rules! update_value_option {
if let Some(v) = &$entity.$field {
if val != *v {
$entity.$field = Some(val);
$update.insert($key, mongodb::bson::to_bson(&$entity.$field).unwrap());
$update.insert(
$key,
mongod::mongodb::bson::to_bson(&$entity.$field).unwrap(),
);
}
} else {
$entity.$field = Some(val);
$update.insert($key, mongodb::bson::to_bson(&$entity.$field).unwrap());
$update.insert(
$key,
mongod::mongodb::bson::to_bson(&$entity.$field).unwrap(),
);
}
}
}