Improve code comments

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-16 23:21:45 +01:00
parent c9a5b66d9c
commit 8dbbcf1885
2 changed files with 10 additions and 6 deletions

View file

@ -56,9 +56,13 @@ impl<'a> Document<'a> {
let tb = txn.clone().lock().await.get_tb(opt.ns(), opt.db(), &id.tb).await; let tb = txn.clone().lock().await.get_tb(opt.ns(), opt.db(), &id.tb).await;
// Return the table or attempt to define it // Return the table or attempt to define it
match tb { match tb {
// The table exists
Ok(tb) => Ok(tb), Ok(tb) => Ok(tb),
// The table doesn't exist
Err(e) => match opt.auth.check(Level::Db) { Err(e) => match opt.auth.check(Level::Db) {
// We can create the table automatically
true => txn.clone().lock().await.add_tb(opt.ns(), opt.db(), &id.tb).await, true => txn.clone().lock().await.add_tb(opt.ns(), opt.db(), &id.tb).await,
// We can't create the table so error
false => Err(e), false => Err(e),
}, },
} }
@ -71,7 +75,7 @@ impl<'a> Document<'a> {
) -> Result<Vec<DefineEventStatement>, Error> { ) -> Result<Vec<DefineEventStatement>, Error> {
// Get the record id // Get the record id
let id = self.id.as_ref().unwrap(); let id = self.id.as_ref().unwrap();
// Get the table definition // Get the event definitions
txn.clone().lock().await.all_ev(opt.ns(), opt.db(), &id.tb).await txn.clone().lock().await.all_ev(opt.ns(), opt.db(), &id.tb).await
} }
// Get the fields for this document // Get the fields for this document
@ -82,7 +86,7 @@ impl<'a> Document<'a> {
) -> Result<Vec<DefineFieldStatement>, Error> { ) -> Result<Vec<DefineFieldStatement>, Error> {
// Get the record id // Get the record id
let id = self.id.as_ref().unwrap(); let id = self.id.as_ref().unwrap();
// Get the table definition // Get the field definitions
txn.clone().lock().await.all_fd(opt.ns(), opt.db(), &id.tb).await txn.clone().lock().await.all_fd(opt.ns(), opt.db(), &id.tb).await
} }
// Get the indexes for this document // Get the indexes for this document
@ -93,7 +97,7 @@ impl<'a> Document<'a> {
) -> Result<Vec<DefineIndexStatement>, Error> { ) -> Result<Vec<DefineIndexStatement>, Error> {
// Get the record id // Get the record id
let id = self.id.as_ref().unwrap(); let id = self.id.as_ref().unwrap();
// Get the table definition // Get the index definitions
txn.clone().lock().await.all_ix(opt.ns(), opt.db(), &id.tb).await txn.clone().lock().await.all_ix(opt.ns(), opt.db(), &id.tb).await
} }
} }

View file

@ -78,15 +78,15 @@ impl Idiom {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into() .into()
} }
// Check if this expression an 'id' field // Check if this expression is an 'id' field
pub(crate) fn is_id(&self) -> bool { pub(crate) fn is_id(&self) -> bool {
self.0.len() == 1 && self.0[0].eq(&ID[0]) self.0.len() == 1 && self.0[0].eq(&ID[0])
} }
// Check if this expression an 'in' field // Check if this expression is an 'in' field
pub(crate) fn is_in(&self) -> bool { pub(crate) fn is_in(&self) -> bool {
self.0.len() == 1 && self.0[0].eq(&IN[0]) self.0.len() == 1 && self.0[0].eq(&IN[0])
} }
// Check if this expression an 'out' field // Check if this expression is an 'out' field
pub(crate) fn is_out(&self) -> bool { pub(crate) fn is_out(&self) -> bool {
self.0.len() == 1 && self.0[0].eq(&OUT[0]) self.0.len() == 1 && self.0[0].eq(&OUT[0])
} }