surrealpatch/lib/src/doc/reset.rs

32 lines
805 B
Rust
Raw Normal View History

use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Statement;
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,
_ctx: &Context<'_>,
_opt: &Options,
_stm: &Statement<'_>,
) -> Result<(), Error> {
// Get the record id
let rid = self.id.as_ref().unwrap();
// Set default field values
self.current.to_mut().def(rid);
// Ensure edge fields are reset
if self.initial.pick(&*EDGE).is_true() {
2023-04-29 15:58:22 +00:00
self.current.to_mut().put(&*EDGE, Value::Bool(true));
self.current.to_mut().put(&*IN, self.initial.pick(&*IN));
self.current.to_mut().put(&*OUT, self.initial.pick(&*OUT));
}
// Carry on
Ok(())
}
}