surrealpatch/lib/src/doc/store.rs

35 lines
785 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;
impl<'a> Document<'a> {
pub async fn store(
&self,
ctx: &Context<'_>,
2022-03-07 18:11:44 +00:00
opt: &Options,
_stm: &Statement<'_>,
) -> Result<(), Error> {
// Check if forced
if !opt.force && !self.changed() {
return Ok(());
}
// Clone transaction
2023-06-21 18:31:15 +00:00
let txn = ctx.try_clone_transaction()?;
// Check if the table is a view
if self.tb(opt, &txn).await?.drop {
return Ok(());
}
// Claim transaction
let mut run = txn.lock().await;
// Get the record id
let rid = self.id.as_ref().unwrap();
// Store the record data
let key = crate::key::thing::new(opt.ns(), opt.db(), &rid.tb, &rid.id);
run.set(key, self).await?;
// Carry on
Ok(())
}
}