diff --git a/lib/src/doc/create.rs b/lib/src/doc/create.rs index 253e78ae..77139264 100644 --- a/lib/src/doc/create.rs +++ b/lib/src/doc/create.rs @@ -16,6 +16,8 @@ impl<'a> Document<'a> { ) -> Result { // Check value type self.admit(ctx, opt, txn, stm).await?; + // Check if exists + self.exist(ctx, opt, txn, stm).await?; // Merge record data self.merge(ctx, opt, txn, stm).await?; // Check if allowed diff --git a/lib/src/doc/exist.rs b/lib/src/doc/exist.rs new file mode 100644 index 00000000..091ea036 --- /dev/null +++ b/lib/src/doc/exist.rs @@ -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(()) + } +} diff --git a/lib/src/doc/mod.rs b/lib/src/doc/mod.rs index dc7289b7..688b5e10 100644 --- a/lib/src/doc/mod.rs +++ b/lib/src/doc/mod.rs @@ -10,6 +10,7 @@ mod document; mod empty; mod erase; mod event; +mod exist; mod grant; mod index; mod insert;