diff --git a/lib/src/doc/document.rs b/lib/src/doc/document.rs index 0fe424b9..835a1255 100644 --- a/lib/src/doc/document.rs +++ b/lib/src/doc/document.rs @@ -1,3 +1,8 @@ +use crate::dbs::Options; +use crate::dbs::Runtime; +use crate::dbs::Transaction; +use crate::err::Error; +use crate::sql::statements::define::DefineTableStatement; use crate::sql::thing::Thing; use crate::sql::value::Value; use std::borrow::Cow; @@ -24,3 +29,22 @@ impl<'a> Document<'a> { } } } + +impl<'a> Document<'a> { + // Check if document has changed + pub fn changed(&self) -> bool { + self.initial != self.current + } + // Get the table for this document + pub async fn tb( + &self, + ctx: &Runtime, + opt: &Options, + txn: &Transaction, + ) -> Result { + // Get the record id + let id = self.id.as_ref().unwrap(); + // Get the table definition + txn.clone().lock().await.get_tb(opt.ns(), opt.db(), &id.tb).await + } +}