2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Statement;
|
2022-02-15 01:00:30 +00:00
|
|
|
use crate::dbs::Transaction;
|
2022-05-30 15:32:26 +00:00
|
|
|
use crate::dbs::Workable;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
2021-03-29 15:43:37 +00:00
|
|
|
|
2022-02-13 19:03:00 +00:00
|
|
|
impl<'a> Document<'a> {
|
2022-02-06 01:14:56 +00:00
|
|
|
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-05-30 15:32:26 +00:00
|
|
|
_stm: &Statement<'_>,
|
2022-02-06 01:14:56 +00:00
|
|
|
) -> Result<(), Error> {
|
2022-04-01 10:17:19 +00:00
|
|
|
// Get the record id
|
|
|
|
let rid = self.id.as_ref().unwrap();
|
2022-02-06 01:14:56 +00:00
|
|
|
// 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 {
|
2022-07-07 09:58:35 +00:00
|
|
|
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?;
|
|
|
|
}
|
2022-02-06 01:14:56 +00:00
|
|
|
// Set default field values
|
2022-04-01 10:17:19 +00:00
|
|
|
self.current.to_mut().def(ctx, opt, txn, rid).await?;
|
2022-02-06 01:14:56 +00:00
|
|
|
// Carry on
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|