2023-03-30 18:30:46 +00:00
|
|
|
use crate::ctx::Context;
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Statement;
|
2023-07-06 14:57:42 +00:00
|
|
|
use crate::dbs::Transaction;
|
2023-08-24 08:19:19 +00:00
|
|
|
use crate::dbs::Workable;
|
2023-03-30 18:30:46 +00:00
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::paths::EDGE;
|
|
|
|
use crate::sql::paths::IN;
|
|
|
|
use crate::sql::paths::OUT;
|
|
|
|
use crate::sql::value::Value;
|
|
|
|
|
|
|
|
impl<'a> Document<'a> {
|
|
|
|
pub async fn reset(
|
|
|
|
&mut self,
|
2023-05-06 00:15:03 +00:00
|
|
|
_ctx: &Context<'_>,
|
|
|
|
_opt: &Options,
|
2023-07-06 14:57:42 +00:00
|
|
|
_txn: &Transaction,
|
2023-03-30 18:30:46 +00:00
|
|
|
_stm: &Statement<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Get the record id
|
|
|
|
let rid = self.id.as_ref().unwrap();
|
|
|
|
// Set default field values
|
2023-07-06 14:57:42 +00:00
|
|
|
self.current.doc.to_mut().def(rid);
|
2023-08-24 08:19:19 +00:00
|
|
|
// This is a RELATE statement, so reset fields
|
|
|
|
if let Workable::Relate(l, r) = &self.extras {
|
|
|
|
self.current.doc.to_mut().put(&*EDGE, Value::Bool(true));
|
|
|
|
self.current.doc.to_mut().put(&*IN, l.clone().into());
|
|
|
|
self.current.doc.to_mut().put(&*OUT, r.clone().into());
|
|
|
|
}
|
|
|
|
// This is an UPDATE of a graph edge, so reset fields
|
2023-07-06 14:57:42 +00:00
|
|
|
if self.initial.doc.pick(&*EDGE).is_true() {
|
|
|
|
self.current.doc.to_mut().put(&*EDGE, Value::Bool(true));
|
|
|
|
self.current.doc.to_mut().put(&*IN, self.initial.doc.pick(&*IN));
|
|
|
|
self.current.doc.to_mut().put(&*OUT, self.initial.doc.pick(&*OUT));
|
2023-03-30 18:30:46 +00:00
|
|
|
}
|
|
|
|
// Carry on
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|