Implement REMOVE statements

This commit is contained in:
Tobie Morgan Hitchcock 2022-03-20 14:27:56 +00:00
parent 9778600304
commit 5ae5046987
2 changed files with 159 additions and 54 deletions

View file

@ -1,30 +1,32 @@
/// KV / /// KV /
/// NS /!ns{$ns} /// NS /!ns{ns}
/// ///
/// Namespace /*{$ns} /// Namespace /*{ns}
/// NL /*{$ns}!nl{$us} /// NL /*{ns}!nl{us}
/// NT /*{$ns}!nt{$tk} /// NT /*{ns}!nt{tk}
/// DB /*{$ns}!db{$db} /// DB /*{ns}!db{db}
/// ///
/// Database /*{$ns}*{$db} /// Database /*{ns}*{db}
/// DL /*{$ns}*{$db}!dl{$us} /// DL /*{ns}*{db}!dl{us}
/// DT /*{$ns}*{$db}!dt{$tk} /// DT /*{ns}*{db}!dt{tk}
/// SC /*{$ns}*{$db}!sc{$sc} /// SC /*{ns}*{db}!sc{sc}
/// ST /*{$ns}*{$db}!st{$sc}!tk{$tk} /// ST /*{ns}*{db}!st{sc}!tk{tk}
/// TB /*{$ns}*{$db}!tb{$tb} /// TB /*{ns}*{db}!tb{tb}
/// ///
/// Table /*{$ns}*{$db}*{$tb} /// Table /*{ns}*{db}*{tb}
/// FT /*{$ns}*{$db}*{$tb}!ft{$ft} /// FT /*{ns}*{db}*{tb}!ft{ft}
/// FD /*{$ns}*{$db}*{$tb}!fd{$fd} /// FD /*{ns}*{db}*{tb}!fd{fd}
/// EV /*{$ns}*{$db}*{$tb}!ev{$ev} /// EV /*{ns}*{db}*{tb}!ev{ev}
/// IX /*{$ns}*{$db}*{$tb}!ix{$ix} /// IX /*{ns}*{db}*{tb}!ix{ix}
/// LV /*{$ns}*{$db}*{$tb}!lv{$lv} /// LV /*{ns}*{db}*{tb}!lv{lv}
/// ///
/// Thing /*{$ns}*{$db}*{$tb}*{$id} /// Thing /*{ns}*{db}*{tb}*{id}
/// ///
/// Guide /*{$ns}*{$db}*{$tb}¤{$ix} /// Graph /*{ns}*{db}*{tb}~{id}{gt}{fk}
/// Index /*{$ns}*{$db}*{$tb}¤{$ix}{$fd} ///
/// Point /*{$ns}*{$db}*{$tb}¤{$ix}{$fd}{$id} /// Guide /*{ns}*{db}*{tb}¤{ix}
/// Index /*{ns}*{db}*{tb}¤{ix}{fd}
/// Point /*{ns}*{db}*{tb}¤{ix}{fd}{id}
/// ///
pub mod database; pub mod database;
pub mod db; pub mod db;

View file

@ -95,13 +95,23 @@ impl RemoveNamespaceStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Kv)?; opt.check(Level::Kv)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::ns::new(&self.name);
run.del(key).await?;
// Delete the resource data
let key = crate::key::namespace::new(&self.name);
run.delp(key, u32::MAX).await?;
// Ok all good
Ok(Value::None)
} }
} }
@ -139,13 +149,23 @@ impl RemoveDatabaseStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Ns)?; opt.check(Level::Ns)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::db::new(opt.ns(), &self.name);
run.del(key).await?;
// Delete the resource data
let key = crate::key::database::new(opt.ns(), &self.name);
run.delp(key, u32::MAX).await?;
// Ok all good
Ok(Value::None)
} }
} }
@ -184,17 +204,38 @@ impl RemoveLoginStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run?
match self.base { match self.base {
Base::Ns => opt.check(Level::Kv)?, Base::Ns => {
Base::Db => opt.check(Level::Ns)?, // Allowed to run?
opt.check(Level::Kv)?;
// Clone transaction
let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::nl::new(opt.ns(), &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
}
Base::Db => {
// Allowed to run?
opt.check(Level::Ns)?;
// Clone transaction
let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::dl::new(opt.ns(), opt.db(), &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
}
_ => unreachable!(), _ => unreachable!(),
} }
// Continue
todo!()
} }
} }
@ -238,17 +279,38 @@ impl RemoveTokenStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run?
match self.base { match self.base {
Base::Ns => opt.check(Level::Kv)?, Base::Ns => {
Base::Db => opt.check(Level::Ns)?, // Allowed to run?
opt.check(Level::Kv)?;
// Clone transaction
let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::nt::new(opt.ns(), &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
}
Base::Db => {
// Allowed to run?
opt.check(Level::Ns)?;
// Clone transaction
let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::dt::new(opt.ns(), opt.db(), &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
}
_ => unreachable!(), _ => unreachable!(),
} }
// Continue
todo!()
} }
} }
@ -291,13 +353,20 @@ impl RemoveScopeStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Db)?; opt.check(Level::Db)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::sc::new(opt.ns(), opt.db(), &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
} }
} }
@ -335,13 +404,23 @@ impl RemoveTableStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Db)?; opt.check(Level::Db)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::tb::new(opt.ns(), opt.db(), &self.name);
run.del(key).await?;
// Remove the resource data
let key = crate::key::table::new(opt.ns(), opt.db(), &self.name);
run.delp(key, u32::MAX).await?;
// Ok all good
Ok(Value::None)
} }
} }
@ -380,13 +459,20 @@ impl RemoveEventStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Db)?; opt.check(Level::Db)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
} }
} }
@ -431,13 +517,20 @@ impl RemoveFieldStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Db)?; opt.check(Level::Db)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::fd::new(opt.ns(), opt.db(), &self.what, &self.name);
run.del(key).await?;
// Ok all good
Ok(Value::None)
} }
} }
@ -482,13 +575,23 @@ impl RemoveIndexStatement {
&self, &self,
_ctx: &Runtime, _ctx: &Runtime,
opt: &Options, opt: &Options,
_txn: &Transaction, txn: &Transaction,
_doc: Option<&Value>, _doc: Option<&Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Allowed to run? // Allowed to run?
opt.check(Level::Db)?; opt.check(Level::Db)?;
// Continue // Clone transaction
todo!() let run = txn.clone();
// Claim transaction
let mut run = run.lock().await;
// Delete the definition
let key = crate::key::ix::new(opt.ns(), opt.db(), &self.what, &self.name);
run.del(key).await?;
// Remove the resource data
let key = crate::key::guide::new(opt.ns(), opt.db(), &self.what, &self.name);
run.delp(key, u32::MAX).await?;
// Ok all good
Ok(Value::None)
} }
} }