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?;
|
self.erase(ctx, opt, txn, stm).await?;
|
||||||
// Purge index data
|
// Purge index data
|
||||||
self.index(ctx, opt, txn, stm).await?;
|
self.index(ctx, opt, txn, stm).await?;
|
||||||
// Store record data
|
// Purge record data
|
||||||
self.store(ctx, opt, txn, stm).await?;
|
self.purge(ctx, opt, txn, stm).await?;
|
||||||
// Run table queries
|
// Run table queries
|
||||||
self.table(ctx, opt, txn, stm).await?;
|
self.table(ctx, opt, txn, stm).await?;
|
||||||
// Run lives queries
|
// Run lives queries
|
||||||
|
|
|
@ -20,6 +20,7 @@ mod lives;
|
||||||
mod merge;
|
mod merge;
|
||||||
mod perms;
|
mod perms;
|
||||||
mod pluck;
|
mod pluck;
|
||||||
|
mod purge;
|
||||||
mod relate;
|
mod relate;
|
||||||
mod select;
|
mod select;
|
||||||
mod store;
|
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::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::key::thing;
|
|
||||||
|
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn store(
|
pub async fn store(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
ctx: &Runtime,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement,
|
_stm: &Statement,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let md = self.id.as_ref().unwrap();
|
// Check if forced
|
||||||
let key = thing::new(opt.ns(), opt.db(), &md.tb, &md.id);
|
if !opt.force && !self.changed() {
|
||||||
txn.clone().lock().await.set(key, self).await?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue