Add common methods on document type
This commit is contained in:
parent
b02ee12aaa
commit
099e1d17ff
1 changed files with 24 additions and 0 deletions
|
@ -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::thing::Thing;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use std::borrow::Cow;
|
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<DefineTableStatement, Error> {
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue