update
This commit is contained in:
parent
97348a9275
commit
0d23326aa2
3 changed files with 26 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
/mongod_derive/target
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub fn model_derive(input: TokenStream) -> TokenStream {
|
||||||
async fn update_values(
|
async fn update_values(
|
||||||
&mut self,
|
&mut self,
|
||||||
obj: &serde_json::Map<String, serde_json::Value>,
|
obj: &serde_json::Map<String, serde_json::Value>,
|
||||||
update: &mut mongodb::bson::Document,
|
update: &mut mongod::mongodb::bson::Document,
|
||||||
) {
|
) {
|
||||||
#( #field_process_code )*
|
#( #field_process_code )*
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@ macro_rules! update_historic_str {
|
||||||
if !(&field.current == val_str) {
|
if !(&field.current == val_str) {
|
||||||
field.update(val_str.to_owned());
|
field.update(val_str.to_owned());
|
||||||
$entity.$field = field;
|
$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 value = Historic::new(Reference::new_raw(val_str).await.unwrap());
|
||||||
let field = $entity.$field.clone().unwrap_or_else(|| value);
|
let field = $entity.$field.clone().unwrap_or_else(|| value);
|
||||||
$entity.$field = Some(field);
|
$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(),
|
.collect(),
|
||||||
);
|
);
|
||||||
$entity.$field = field;
|
$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 let Ok(val) = serde_json::from_value::<$t>(val.clone()) {
|
||||||
if val != $entity.$field {
|
if val != $entity.$field {
|
||||||
$entity.$field = val;
|
$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 let Some(v) = &$entity.$field {
|
||||||
if val != *v {
|
if val != *v {
|
||||||
$entity.$field = Some(val);
|
$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 {
|
} else {
|
||||||
$entity.$field = Some(val);
|
$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(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue