Finish implementation of record storing / purging
This commit is contained in:
parent
099e1d17ff
commit
0df347732d
4 changed files with 62 additions and 7 deletions
|
@ -24,8 +24,8 @@ impl<'a> Document<'a> {
|
|||
self.erase(ctx, opt, txn, stm).await?;
|
||||
// Purge index data
|
||||
self.index(ctx, opt, txn, stm).await?;
|
||||
// Store record data
|
||||
self.store(ctx, opt, txn, stm).await?;
|
||||
// Purge record data
|
||||
self.purge(ctx, opt, txn, stm).await?;
|
||||
// Run table queries
|
||||
self.table(ctx, opt, txn, stm).await?;
|
||||
// Run lives queries
|
||||
|
|
|
@ -20,6 +20,7 @@ mod lives;
|
|||
mod merge;
|
||||
mod perms;
|
||||
mod pluck;
|
||||
mod purge;
|
||||
mod relate;
|
||||
mod select;
|
||||
mod store;
|
||||
|
|
40
lib/src/doc/purge.rs
Normal file
40
lib/src/doc/purge.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use crate::dbs::Options;
|
||||
use crate::dbs::Runtime;
|
||||
use crate::dbs::Statement;
|
||||
use crate::dbs::Transaction;
|
||||
use crate::doc::Document;
|
||||
use crate::err::Error;
|
||||
|
||||
impl<'a> Document<'a> {
|
||||
pub async fn purge(
|
||||
&self,
|
||||
ctx: &Runtime,
|
||||
opt: &Options,
|
||||
txn: &Transaction,
|
||||
_stm: &Statement,
|
||||
) -> Result<(), Error> {
|
||||
// Check if forced
|
||||
if !opt.force && !self.changed() {
|
||||
return Ok(());
|
||||
}
|
||||
// Check if the table is a view
|
||||
if self.tb(ctx, opt, txn).await?.drop {
|
||||
return Ok(());
|
||||
}
|
||||
// Clone transaction
|
||||
let run = txn.clone();
|
||||
// Claim transaction
|
||||
let mut run = run.lock().await;
|
||||
// Get the record id
|
||||
let rid = self.id.as_ref().unwrap();
|
||||
// Purge the record data
|
||||
let key = crate::key::thing::new(opt.ns(), opt.db(), &rid.tb, &rid.id);
|
||||
run.del(key).await?;
|
||||
// Remove the graph data
|
||||
let beg = crate::key::graph::prefix(opt.ns(), opt.db(), &rid.tb, &rid.id);
|
||||
let end = crate::key::graph::suffix(opt.ns(), opt.db(), &rid.tb, &rid.id);
|
||||
run.delr(beg..end, u32::MAX).await?;
|
||||
// Carry on
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -4,19 +4,33 @@ use crate::dbs::Statement;
|
|||
use crate::dbs::Transaction;
|
||||
use crate::doc::Document;
|
||||
use crate::err::Error;
|
||||
use crate::key::thing;
|
||||
|
||||
impl<'a> Document<'a> {
|
||||
pub async fn store(
|
||||
&self,
|
||||
_ctx: &Runtime,
|
||||
ctx: &Runtime,
|
||||
opt: &Options,
|
||||
txn: &Transaction,
|
||||
_stm: &Statement,
|
||||
) -> Result<(), Error> {
|
||||
let md = self.id.as_ref().unwrap();
|
||||
let key = thing::new(opt.ns(), opt.db(), &md.tb, &md.id);
|
||||
txn.clone().lock().await.set(key, self).await?;
|
||||
// Check if forced
|
||||
if !opt.force && !self.changed() {
|
||||
return Ok(());
|
||||
}
|
||||
// Check if the table is a view
|
||||
if self.tb(ctx, opt, txn).await?.drop {
|
||||
return Ok(());
|
||||
}
|
||||
// Clone transaction
|
||||
let run = txn.clone();
|
||||
// Claim transaction
|
||||
let mut run = run.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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue