Add function for checking if record already exists
This commit is contained in:
parent
9f7527c01a
commit
c57c313c47
3 changed files with 30 additions and 0 deletions
|
@ -16,6 +16,8 @@ impl<'a> Document<'a> {
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
// Check value type
|
// Check value type
|
||||||
self.admit(ctx, opt, txn, stm).await?;
|
self.admit(ctx, opt, txn, stm).await?;
|
||||||
|
// Check if exists
|
||||||
|
self.exist(ctx, opt, txn, stm).await?;
|
||||||
// Merge record data
|
// Merge record data
|
||||||
self.merge(ctx, opt, txn, stm).await?;
|
self.merge(ctx, opt, txn, stm).await?;
|
||||||
// Check if allowed
|
// Check if allowed
|
||||||
|
|
27
lib/src/doc/exist.rs
Normal file
27
lib/src/doc/exist.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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 exist(
|
||||||
|
&self,
|
||||||
|
_ctx: &Runtime,
|
||||||
|
_opt: &Options,
|
||||||
|
_txn: &Transaction,
|
||||||
|
_stm: &Statement,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
// Check if this record exists
|
||||||
|
if let Some(id) = &self.id {
|
||||||
|
if self.current.is_some() {
|
||||||
|
return Err(Error::RecordExists {
|
||||||
|
thing: id.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Carry on
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ mod document;
|
||||||
mod empty;
|
mod empty;
|
||||||
mod erase;
|
mod erase;
|
||||||
mod event;
|
mod event;
|
||||||
|
mod exist;
|
||||||
mod grant;
|
mod grant;
|
||||||
mod index;
|
mod index;
|
||||||
mod insert;
|
mod insert;
|
||||||
|
|
Loading…
Reference in a new issue