diff --git a/lib/src/doc/document.rs b/lib/src/doc/document.rs index 433673d9..708c2815 100644 --- a/lib/src/doc/document.rs +++ b/lib/src/doc/document.rs @@ -56,9 +56,13 @@ impl<'a> Document<'a> { let tb = txn.clone().lock().await.get_tb(opt.ns(), opt.db(), &id.tb).await; // Return the table or attempt to define it match tb { + // The table exists Ok(tb) => Ok(tb), + // The table doesn't exist 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, + // We can't create the table so error false => Err(e), }, } @@ -71,7 +75,7 @@ impl<'a> Document<'a> { ) -> Result, Error> { // Get the record id 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 } // Get the fields for this document @@ -82,7 +86,7 @@ impl<'a> Document<'a> { ) -> Result, Error> { // Get the record id 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 } // Get the indexes for this document @@ -93,7 +97,7 @@ impl<'a> Document<'a> { ) -> Result, Error> { // Get the record id 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 } } diff --git a/lib/src/sql/idiom.rs b/lib/src/sql/idiom.rs index ee39c3fe..e0f143d5 100644 --- a/lib/src/sql/idiom.rs +++ b/lib/src/sql/idiom.rs @@ -78,15 +78,15 @@ impl Idiom { .collect::>() .into() } - // Check if this expression an 'id' field + // Check if this expression is an 'id' field pub(crate) fn is_id(&self) -> bool { 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 { 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 { self.0.len() == 1 && self.0[0].eq(&OUT[0]) }