2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2022-01-20 23:00:57 +00:00
|
|
|
use crate::dbs::Options;
|
2022-02-15 01:00:30 +00:00
|
|
|
use crate::dbs::Transaction;
|
2022-01-20 23:00:57 +00:00
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::value::Value;
|
|
|
|
|
|
|
|
impl Value {
|
|
|
|
pub async fn merge(
|
|
|
|
&mut self,
|
2022-05-14 12:35:08 +00:00
|
|
|
ctx: &Context<'_>,
|
2022-02-06 21:06:52 +00:00
|
|
|
opt: &Options,
|
2022-02-15 03:33:16 +00:00
|
|
|
txn: &Transaction,
|
2022-07-07 09:58:35 +00:00
|
|
|
val: Value,
|
2022-01-20 23:00:57 +00:00
|
|
|
) -> Result<(), Error> {
|
2022-07-07 09:58:35 +00:00
|
|
|
match val {
|
2022-09-29 10:09:20 +00:00
|
|
|
v if v.is_object() => {
|
|
|
|
for k in v.every(false).iter() {
|
|
|
|
match v.get(ctx, opt, txn, &k.0).await? {
|
|
|
|
Value::None => self.del(ctx, opt, txn, &k.0).await?,
|
|
|
|
v => self.set(ctx, opt, txn, &k.0, v).await?,
|
|
|
|
}
|
2022-01-20 23:00:57 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-02-13 23:39:10 +00:00
|
|
|
_ => Ok(()),
|
2022-01-20 23:00:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|