surrealpatch/lib/src/doc/merge.rs

32 lines
816 B
Rust
Raw Normal View History

use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Statement;
use crate::dbs::Transaction;
2022-05-30 15:32:26 +00:00
use crate::dbs::Workable;
use crate::doc::Document;
use crate::err::Error;
2021-03-29 15:43:37 +00:00
impl<'a> Document<'a> {
pub async fn merge(
&mut self,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
2022-05-30 15:32:26 +00:00
_stm: &Statement<'_>,
) -> Result<(), Error> {
2022-04-01 10:17:19 +00:00
// Get the record id
let rid = self.id.as_ref().unwrap();
// Set default field values
2022-04-01 10:17:19 +00:00
self.current.to_mut().def(ctx, opt, txn, rid).await?;
2022-05-30 15:32:26 +00:00
// This is an INSERT statement
if let Workable::Insert(v) = &self.extras {
let v = v.compute(ctx, opt, txn, Some(&self.current)).await?;
2022-05-30 15:32:26 +00:00
self.current.to_mut().merge(ctx, opt, txn, v).await?;
}
// Set default field values
2022-04-01 10:17:19 +00:00
self.current.to_mut().def(ctx, opt, txn, rid).await?;
// Carry on
Ok(())
}
}