diff --git a/src/dbs/dbs.rs b/src/dbs/dbs.rs index 4e4be7f3..a417f7e1 100644 --- a/src/dbs/dbs.rs +++ b/src/dbs/dbs.rs @@ -1,4 +1,5 @@ use crate::dbs::executor::Executor; +use crate::dbs::options::Options; use crate::dbs::response::Responses; use crate::dbs::session::Session; use crate::dbs::variables::Attach; @@ -7,8 +8,11 @@ use crate::err::Error; use crate::sql; use crate::sql::query::Query; use hyper::body::Sender; +use std::sync::Arc; pub async fn execute(txt: &str, session: Session, vars: Variables) -> Result { + // Create a new query options + let mut opt = Options::default(); // Create a new query executor let mut exe = Executor::new(); // Create a new execution context @@ -18,12 +22,14 @@ pub async fn execute(txt: &str, session: Session, vars: Variables) -> Result Result { + // Create a new query options + let mut opt = Options::default(); // Create a new query executor let mut exe = Executor::new(); // Store session info on context @@ -31,18 +37,20 @@ pub async fn process(ast: Query, session: Session, vars: Variables) -> Result Result<(), Error> { + // Create a new query options + let mut opt = Options::default(); // Create a new query executor let mut exe = Executor::new(); // Create a new execution context let ctx = session.context(); // Process database export - exe.ns = session.ns; - exe.db = session.db; - exe.export(ctx, sender).await + opt.ns = session.ns.map(Arc::new); + opt.db = session.db.map(Arc::new); + exe.export(ctx, opt, sender).await } diff --git a/src/dbs/executor.rs b/src/dbs/executor.rs index 7c9e8325..1b68b591 100644 --- a/src/dbs/executor.rs +++ b/src/dbs/executor.rs @@ -1,7 +1,6 @@ use crate::ctx::Context; use crate::dbs::response::{Response, Responses, Status}; use crate::dbs::Auth; -use crate::dbs::Level; use crate::dbs::Options; use crate::dbs::Runtime; use crate::err::Error; @@ -16,38 +15,19 @@ use std::time::Instant; #[derive(Default)] pub struct Executor<'a> { - pub id: Option, - pub ns: Option, - pub db: Option, - pub txn: Option>>>, - pub err: Option, + txn: Option>>>, + err: Option, } impl<'a> Executor<'a> { pub fn new() -> Executor<'a> { Executor { - id: None, - ns: None, - db: None, ..Executor::default() } } - pub fn check(&self, opt: &Options, level: Level) -> Result<(), Error> { - if opt.auth.check(level) == false { - return Err(Error::QueryPermissionsError); - } - if self.ns.is_none() { - return Err(Error::NsError); - } - if self.db.is_none() { - return Err(Error::DbError); - } - Ok(()) - } - async fn begin(&mut self) -> bool { - match self.txn { + match &self.txn { Some(_) => false, None => match transaction(true, false).await { Ok(v) => { @@ -65,15 +45,25 @@ impl<'a> Executor<'a> { async fn commit(&mut self, local: bool) { if local { match &self.txn { - Some(txn) => { - let txn = txn.clone(); - let mut txn = txn.lock().await; - if let Err(e) = txn.commit().await { - self.err = Some(e); + Some(txn) => match &self.err { + Some(_) => { + let txn = txn.clone(); + let mut txn = txn.lock().await; + if let Err(e) = txn.cancel().await { + self.err = Some(e); + } + self.txn = None; } - self.txn = None; - } - None => unreachable!(), + None => { + let txn = txn.clone(); + let mut txn = txn.lock().await; + if let Err(e) = txn.commit().await { + self.err = Some(e); + } + self.txn = None; + } + }, + None => (), } } } @@ -94,13 +84,6 @@ impl<'a> Executor<'a> { } } - async fn finish(&mut self, res: &Result, local: bool) { - match res { - Ok(_) => self.commit(local).await, - Err(_) => self.cancel(local).await, - } - } - fn buf_cancel(&self, v: Response) -> Response { Response { sql: v.sql, @@ -127,13 +110,16 @@ impl<'a> Executor<'a> { } } - pub async fn execute(&mut self, mut ctx: Runtime, qry: Query) -> Result { + pub async fn execute( + &mut self, + mut ctx: Runtime, + mut opt: Options, + qry: Query, + ) -> Result { // Initialise buffer of responses let mut buf: Vec = vec![]; // Initialise array of responses let mut out: Vec = vec![]; - // Create a new options - let mut opt = Options::new(&Auth::No); // Process all statements in query for stm in qry.statements().iter() { // Log the statement @@ -159,39 +145,56 @@ impl<'a> Executor<'a> { continue; } // Begin a new transaction - Statement::Begin(stm) => { - let res = stm.compute(&ctx, &opt, self, None).await; - if res.is_err() { - self.err = res.err() - }; + Statement::Begin(_) => { + self.begin().await; continue; } // Cancel a running transaction - Statement::Cancel(stm) => { - let res = stm.compute(&ctx, &opt, self, None).await; - if res.is_err() { - self.err = res.err() - }; + Statement::Cancel(_) => { + self.cancel(true).await; buf = buf.into_iter().map(|v| self.buf_cancel(v)).collect(); out.append(&mut buf); self.txn = None; continue; } // Commit a running transaction - Statement::Commit(stm) => { - let res = stm.compute(&ctx, &opt, self, None).await; - if res.is_err() { - self.err = res.err() - }; + Statement::Commit(_) => { + self.commit(true).await; buf = buf.into_iter().map(|v| self.buf_commit(v)).collect(); out.append(&mut buf); self.txn = None; continue; } - // Commit a running transaction + // Switch to a different NS or DB Statement::Use(stm) => { - let res = stm.compute(&ctx, &opt, self, None).await; - res + if let Some(ref ns) = stm.ns { + match &*opt.auth { + Auth::No => opt.ns = Some(Arc::new(ns.to_owned())), + Auth::Kv => opt.ns = Some(Arc::new(ns.to_owned())), + Auth::Ns(v) if v == ns => opt.ns = Some(Arc::new(ns.to_owned())), + _ => { + opt.ns = None; + return Err(Error::NsAuthenticationError { + ns: ns.to_owned(), + }); + } + } + } + if let Some(ref db) = stm.db { + match &*opt.auth { + Auth::No => opt.db = Some(Arc::new(db.to_owned())), + Auth::Kv => opt.db = Some(Arc::new(db.to_owned())), + Auth::Ns(_) => opt.db = Some(Arc::new(db.to_owned())), + Auth::Db(_, v) if v == db => opt.db = Some(Arc::new(db.to_owned())), + _ => { + opt.db = None; + return Err(Error::DbAuthenticationError { + db: db.to_owned(), + }); + } + } + } + Ok(Value::None) } // Process param definition statements Statement::Set(stm) => { @@ -235,7 +238,10 @@ impl<'a> Executor<'a> { None => res, }; // Finalise transaction - self.finish(&res, loc).await; + match &res { + Ok(_) => self.commit(loc).await, + Err(_) => self.cancel(loc).await, + }; // Return the result res } diff --git a/src/dbs/export.rs b/src/dbs/export.rs index 2fc0b796..f1f1f067 100644 --- a/src/dbs/export.rs +++ b/src/dbs/export.rs @@ -1,4 +1,5 @@ use crate::dbs::Executor; +use crate::dbs::Options; use crate::dbs::Runtime; use crate::err::Error; use crate::kvs::transaction; @@ -12,7 +13,12 @@ macro_rules! output { } impl<'a> Executor<'a> { - pub async fn export(&mut self, ctx: Runtime, mut chn: Sender) -> Result<(), Error> { + pub async fn export( + &mut self, + ctx: Runtime, + opt: Options, + mut chn: Sender, + ) -> Result<(), Error> { // Start a new transaction let txn = transaction(false, false).await?; // Output OPTIONS diff --git a/src/dbs/iterate.rs b/src/dbs/iterate.rs index a1c148d4..2c3ef816 100644 --- a/src/dbs/iterate.rs +++ b/src/dbs/iterate.rs @@ -15,7 +15,7 @@ impl Value { pub async fn iterate( self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ite: &mut Iterator<'_>, ) -> Result<(), Error> { @@ -35,7 +35,7 @@ impl Array { pub async fn iterate( self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ite: &mut Iterator<'_>, ) -> Result<(), Error> { @@ -56,7 +56,7 @@ impl Model { pub async fn iterate( self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ite: &mut Iterator<'_>, ) -> Result<(), Error> { @@ -90,7 +90,7 @@ impl Thing { pub async fn iterate( self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ite: &mut Iterator<'_>, ) -> Result<(), Error> { @@ -102,7 +102,7 @@ impl Table { pub async fn iterate( self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ite: &mut Iterator<'_>, ) -> Result<(), Error> { diff --git a/src/dbs/iterator.rs b/src/dbs/iterator.rs index 12301361..f442a81f 100644 --- a/src/dbs/iterator.rs +++ b/src/dbs/iterator.rs @@ -63,10 +63,11 @@ impl<'a> Iterator<'a> { })) } + // Process the records and output pub async fn output( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ) -> Result { // Log the statement @@ -96,35 +97,35 @@ impl<'a> Iterator<'a> { } #[inline] - fn output_split(&mut self, ctx: &Runtime, opt: &Options<'_>, exe: &Executor) { + fn output_split(&mut self, ctx: &Runtime, opt: &Options, exe: &Executor) { if self.split.is_some() { // Ignore } } #[inline] - fn output_group(&mut self, ctx: &Runtime, opt: &Options<'_>, exe: &Executor) { + fn output_group(&mut self, ctx: &Runtime, opt: &Options, exe: &Executor) { if self.group.is_some() { // Ignore } } #[inline] - fn output_order(&mut self, ctx: &Runtime, opt: &Options<'_>, exe: &Executor) { + fn output_order(&mut self, ctx: &Runtime, opt: &Options, exe: &Executor) { if self.order.is_some() { // Ignore } } #[inline] - fn output_start(&mut self, ctx: &Runtime, opt: &Options<'_>, exe: &Executor) { + fn output_start(&mut self, ctx: &Runtime, opt: &Options, exe: &Executor) { if let Some(v) = self.start { self.results = mem::take(&mut self.results).into_iter().skip(v.0).collect(); } } #[inline] - fn output_limit(&mut self, ctx: &Runtime, opt: &Options<'_>, exe: &Executor) { + fn output_limit(&mut self, ctx: &Runtime, opt: &Options, exe: &Executor) { if let Some(v) = self.limit { self.results = mem::take(&mut self.results).into_iter().take(v.0).collect(); } @@ -133,7 +134,7 @@ impl<'a> Iterator<'a> { async fn iterate( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ) -> Result<(), Error> { match self.parallel { @@ -167,7 +168,7 @@ impl<'a> Iterator<'a> { pub async fn process( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, thg: Option, val: Value, diff --git a/src/dbs/options.rs b/src/dbs/options.rs index 311d5e91..847417ee 100644 --- a/src/dbs/options.rs +++ b/src/dbs/options.rs @@ -1,7 +1,8 @@ use crate::cnf; use crate::dbs::Auth; +use crate::dbs::Level; use crate::err::Error; -use crate::sql::version::Version; +use std::sync::Arc; // An Options is passed around when processing a set of query // statements. An Options contains specific information for how @@ -11,29 +12,41 @@ use crate::sql::version::Version; // when importing data, where these queries might fail). #[derive(Clone, Debug, Eq, PartialEq)] -pub struct Options<'a> { - pub auth: &'a Auth, - pub dive: usize, // How many subqueries have we gone into? - pub debug: bool, // Should we debug query response SQL? - pub force: bool, // Should we force tables/events to re-run? - pub fields: bool, // Should we process field queries? - pub events: bool, // Should we process event queries? - pub tables: bool, // Should we process table queries? - pub futures: bool, // Should we process function futures? - pub version: Option<&'a Version>, // Current +pub struct Options { + // Currently selected NS + pub ns: Option>, + // Currently selected DB + pub db: Option>, + // Connection authentication data + pub auth: Arc, + // How many subqueries have we gone into? + pub dive: usize, + // Should we debug query response SQL? + pub debug: bool, + // Should we force tables/events to re-run? + pub force: bool, + // Should we process field queries? + pub fields: bool, + // Should we process event queries? + pub events: bool, + // Should we process table queries? + pub tables: bool, + // Should we process function futures? + pub futures: bool, } -impl<'a> Default for Options<'a> { +impl Default for Options { fn default() -> Self { - Options::new(&Auth::No) + Options::new(Auth::No) } } -impl<'a> Options<'a> { +impl Options { // Create a new Options object - pub fn new(auth: &'a Auth) -> Options<'a> { + pub fn new(auth: Auth) -> Options { Options { - auth, + ns: None, + db: None, dive: 0, debug: false, force: false, @@ -41,14 +54,27 @@ impl<'a> Options<'a> { events: true, tables: true, futures: false, - version: None, + auth: Arc::new(auth), } } + // Get currently selected NS + pub fn ns(&self) -> &String { + self.ns.as_ref().unwrap() + } + + // Get currently selected DB + pub fn db(&self) -> &String { + self.db.as_ref().unwrap() + } + // Create a new Options object for a subquery - pub fn dive(&self) -> Result, Error> { + pub fn dive(&self) -> Result { if self.dive < cnf::MAX_RECURSIVE_QUERIES { Ok(Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), dive: self.dive + 1, ..*self }) @@ -60,48 +86,66 @@ impl<'a> Options<'a> { } // Create a new Options object for a subquery - pub fn debug(&self, v: bool) -> Options<'a> { + pub fn debug(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), debug: v, ..*self } } // Create a new Options object for a subquery - pub fn force(&self, v: bool) -> Options<'a> { + pub fn force(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), force: v, ..*self } } // Create a new Options object for a subquery - pub fn fields(&self, v: bool) -> Options<'a> { + pub fn fields(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), fields: v, ..*self } } // Create a new Options object for a subquery - pub fn events(&self, v: bool) -> Options<'a> { + pub fn events(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), events: v, ..*self } } // Create a new Options object for a subquery - pub fn tables(&self, v: bool) -> Options<'a> { + pub fn tables(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), tables: v, ..*self } } // Create a new Options object for a subquery - pub fn import(&self, v: bool) -> Options<'a> { + pub fn import(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), fields: v, events: v, tables: v, @@ -110,18 +154,27 @@ impl<'a> Options<'a> { } // Create a new Options object for a subquery - pub fn futures(&self, v: bool) -> Options<'a> { + pub fn futures(&self, v: bool) -> Options { Options { + auth: self.auth.clone(), + ns: self.ns.clone(), + db: self.db.clone(), futures: v, ..*self } } - // Create a new Options object for a subquery - pub fn version(&self, v: Option<&'a Version>) -> Options<'a> { - Options { - version: v, - ..*self + // Check whether the authentication permissions are ok + pub fn check(&self, level: Level) -> Result<(), Error> { + if self.auth.check(level) == false { + return Err(Error::QueryPermissionsError); } + if self.ns.is_none() { + return Err(Error::NsError); + } + if self.db.is_none() { + return Err(Error::DbError); + } + Ok(()) } } diff --git a/src/dbs/test.rs b/src/dbs/test.rs index ab873b1d..060e11a4 100644 --- a/src/dbs/test.rs +++ b/src/dbs/test.rs @@ -3,7 +3,7 @@ use crate::dbs::executor::Executor; use crate::dbs::Options; use crate::dbs::Runtime; -pub fn mock<'a>() -> (Runtime, Options<'a>, Executor<'a>) { +pub fn mock<'a>() -> (Runtime, Options, Executor<'a>) { let ctx = Context::default().freeze(); let opt = Options::default(); let exe = Executor::new(); diff --git a/src/doc/admit.rs b/src/doc/admit.rs index ba462f18..662655ea 100644 --- a/src/doc/admit.rs +++ b/src/doc/admit.rs @@ -9,7 +9,7 @@ impl Document { pub async fn admit( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/allow.rs b/src/doc/allow.rs index f79c4b96..ab262fdf 100644 --- a/src/doc/allow.rs +++ b/src/doc/allow.rs @@ -9,7 +9,7 @@ impl Document { pub async fn allow( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/check.rs b/src/doc/check.rs index 7ed1da0f..a38c5907 100644 --- a/src/doc/check.rs +++ b/src/doc/check.rs @@ -9,7 +9,7 @@ impl Document { pub async fn check( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/compute.rs b/src/doc/compute.rs index a43cb0dc..2877468e 100644 --- a/src/doc/compute.rs +++ b/src/doc/compute.rs @@ -10,7 +10,7 @@ impl Document { pub async fn compute( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/create.rs b/src/doc/create.rs index 43214a6e..809f1394 100644 --- a/src/doc/create.rs +++ b/src/doc/create.rs @@ -10,7 +10,7 @@ impl Document { pub async fn create( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/delete.rs b/src/doc/delete.rs index 56a042af..dd9da198 100644 --- a/src/doc/delete.rs +++ b/src/doc/delete.rs @@ -10,7 +10,7 @@ impl Document { pub async fn delete( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/erase.rs b/src/doc/erase.rs index 5cee207e..1ccd3cb9 100644 --- a/src/doc/erase.rs +++ b/src/doc/erase.rs @@ -9,7 +9,7 @@ impl Document { pub async fn erase( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/event.rs b/src/doc/event.rs index 11fb59d2..1226e2e5 100644 --- a/src/doc/event.rs +++ b/src/doc/event.rs @@ -9,7 +9,7 @@ impl Document { pub async fn event( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/index.rs b/src/doc/index.rs index cb1b70d0..3e6a9b3a 100644 --- a/src/doc/index.rs +++ b/src/doc/index.rs @@ -9,7 +9,7 @@ impl Document { pub async fn index( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/insert.rs b/src/doc/insert.rs index 1358ef2b..dd34dfdf 100644 --- a/src/doc/insert.rs +++ b/src/doc/insert.rs @@ -10,7 +10,7 @@ impl Document { pub async fn insert( &mut self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/lives.rs b/src/doc/lives.rs index a9fac56d..83529341 100644 --- a/src/doc/lives.rs +++ b/src/doc/lives.rs @@ -9,7 +9,7 @@ impl Document { pub async fn lives( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/merge.rs b/src/doc/merge.rs index d565e271..5cc6feb5 100644 --- a/src/doc/merge.rs +++ b/src/doc/merge.rs @@ -12,7 +12,7 @@ impl Document { pub async fn merge( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/pluck.rs b/src/doc/pluck.rs index 490c5afd..e5301f2e 100644 --- a/src/doc/pluck.rs +++ b/src/doc/pluck.rs @@ -13,7 +13,7 @@ impl Document { pub async fn pluck( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/relate.rs b/src/doc/relate.rs index d89dd968..90070c2e 100644 --- a/src/doc/relate.rs +++ b/src/doc/relate.rs @@ -10,7 +10,7 @@ impl Document { pub async fn relate( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/select.rs b/src/doc/select.rs index 8b13ea88..f6087b8a 100644 --- a/src/doc/select.rs +++ b/src/doc/select.rs @@ -10,7 +10,7 @@ impl Document { pub async fn select( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/doc/store.rs b/src/doc/store.rs index a0847065..752bfa0d 100644 --- a/src/doc/store.rs +++ b/src/doc/store.rs @@ -9,7 +9,7 @@ impl Document { pub async fn store( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/table.rs b/src/doc/table.rs index 2f1358b5..d031e84f 100644 --- a/src/doc/table.rs +++ b/src/doc/table.rs @@ -9,7 +9,7 @@ impl Document { pub async fn table( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _stm: &Statement<'_>, ) -> Result<(), Error> { diff --git a/src/doc/update.rs b/src/doc/update.rs index f2139325..156f5430 100644 --- a/src/doc/update.rs +++ b/src/doc/update.rs @@ -10,7 +10,7 @@ impl Document { pub async fn update( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, stm: &Statement<'_>, ) -> Result { diff --git a/src/sql/array.rs b/src/sql/array.rs index 13ee45a4..80aa8052 100644 --- a/src/sql/array.rs +++ b/src/sql/array.rs @@ -116,7 +116,7 @@ impl Array { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/expression.rs b/src/sql/expression.rs index cb38b572..6f713fe0 100644 --- a/src/sql/expression.rs +++ b/src/sql/expression.rs @@ -31,7 +31,7 @@ impl Expression { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/function.rs b/src/sql/function.rs index fb580ee8..fa7fac1e 100644 --- a/src/sql/function.rs +++ b/src/sql/function.rs @@ -34,7 +34,7 @@ impl Function { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/idiom.rs b/src/sql/idiom.rs index c87a6dfc..02c8bf76 100644 --- a/src/sql/idiom.rs +++ b/src/sql/idiom.rs @@ -71,7 +71,7 @@ impl Idiom { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/object.rs b/src/sql/object.rs index 20b8fee8..55c21eb7 100644 --- a/src/sql/object.rs +++ b/src/sql/object.rs @@ -95,7 +95,7 @@ impl Object { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/param.rs b/src/sql/param.rs index 5bb34249..1350d8a0 100644 --- a/src/sql/param.rs +++ b/src/sql/param.rs @@ -29,7 +29,7 @@ impl Param { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statement.rs b/src/sql/statement.rs index 5d9ac4d9..26273543 100644 --- a/src/sql/statement.rs +++ b/src/sql/statement.rs @@ -108,7 +108,7 @@ impl Statement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statements/begin.rs b/src/sql/statements/begin.rs index 59ccb22e..b2f13d22 100644 --- a/src/sql/statements/begin.rs +++ b/src/sql/statements/begin.rs @@ -1,42 +1,15 @@ -use crate::dbs::Executor; -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::err::Error; -use crate::kvs::transaction; use crate::sql::comment::shouldbespace; use crate::sql::error::IResult; -use crate::sql::value::Value; -use futures::lock::Mutex; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::combinator::opt; use nom::sequence::tuple; use serde::{Deserialize, Serialize}; use std::fmt; -use std::sync::Arc; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct BeginStatement; -impl BeginStatement { - pub async fn compute( - &self, - _ctx: &Runtime, - _opt: &Options<'_>, - exe: &mut Executor<'_>, - _doc: Option<&Value>, - ) -> Result { - match &exe.txn { - Some(_) => Ok(Value::None), - None => { - let txn = transaction(true, false).await?; - exe.txn = Some(Arc::new(Mutex::new(txn))); - Ok(Value::None) - } - } - } -} - impl fmt::Display for BeginStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "BEGIN TRANSACTION") diff --git a/src/sql/statements/cancel.rs b/src/sql/statements/cancel.rs index b936bdbe..14375e3b 100644 --- a/src/sql/statements/cancel.rs +++ b/src/sql/statements/cancel.rs @@ -1,10 +1,5 @@ -use crate::dbs::Executor; -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::err::Error; use crate::sql::comment::shouldbespace; use crate::sql::error::IResult; -use crate::sql::value::Value; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::combinator::opt; @@ -15,28 +10,6 @@ use std::fmt; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct CancelStatement; -impl CancelStatement { - pub async fn compute( - &self, - _ctx: &Runtime, - _opt: &Options<'_>, - exe: &Executor<'_>, - _doc: Option<&Value>, - ) -> Result { - match &exe.txn { - Some(txn) => { - let txn = txn.clone(); - let mut txn = txn.lock().await; - match txn.cancel().await { - Ok(_) => Ok(Value::None), - Err(e) => Err(e), - } - } - None => Ok(Value::None), - } - } -} - impl fmt::Display for CancelStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "CANCEL TRANSACTION") diff --git a/src/sql/statements/commit.rs b/src/sql/statements/commit.rs index c9ba83a4..279737de 100644 --- a/src/sql/statements/commit.rs +++ b/src/sql/statements/commit.rs @@ -1,10 +1,5 @@ -use crate::dbs::Executor; -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::err::Error; use crate::sql::comment::shouldbespace; use crate::sql::error::IResult; -use crate::sql::value::Value; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::combinator::opt; @@ -15,38 +10,6 @@ use std::fmt; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct CommitStatement; -impl CommitStatement { - pub async fn compute( - &self, - _ctx: &Runtime, - _opt: &Options<'_>, - exe: &Executor<'_>, - _doc: Option<&Value>, - ) -> Result { - match &exe.txn { - Some(txn) => match &exe.err { - Some(_) => { - let txn = txn.clone(); - let mut txn = txn.lock().await; - match txn.cancel().await { - Ok(_) => Ok(Value::None), - Err(e) => Err(e), - } - } - None => { - let txn = txn.clone(); - let mut txn = txn.lock().await; - match txn.commit().await { - Ok(_) => Ok(Value::None), - Err(e) => Err(e), - } - } - }, - None => Ok(Value::None), - } - } -} - impl fmt::Display for CommitStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "COMMIT TRANSACTION") diff --git a/src/sql/statements/create.rs b/src/sql/statements/create.rs index 5cdfa515..871f1d90 100644 --- a/src/sql/statements/create.rs +++ b/src/sql/statements/create.rs @@ -32,12 +32,12 @@ impl CreateStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::No)?; + opt.check(Level::No)?; // Create a new iterator let mut i = Iterator::new(); // Pass in current statement diff --git a/src/sql/statements/define.rs b/src/sql/statements/define.rs index 7e07c1ed..a42c54c8 100644 --- a/src/sql/statements/define.rs +++ b/src/sql/statements/define.rs @@ -42,7 +42,7 @@ impl DefineStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { @@ -103,12 +103,12 @@ impl DefineNamespaceStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Kv)?; + opt.check(Level::Kv)?; // Continue todo!() } @@ -147,12 +147,12 @@ impl DefineDatabaseStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Ns)?; + opt.check(Level::Ns)?; // Continue todo!() } @@ -196,14 +196,14 @@ impl DefineLoginStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? match self.base { - Base::Ns => exe.check(opt, Level::Kv)?, - Base::Db => exe.check(opt, Level::Ns)?, + Base::Ns => opt.check(Level::Kv)?, + Base::Db => opt.check(Level::Ns)?, _ => unreachable!(), } // Continue @@ -294,14 +294,14 @@ impl DefineTokenStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? match self.base { - Base::Ns => exe.check(opt, Level::Kv)?, - Base::Db => exe.check(opt, Level::Ns)?, + Base::Ns => opt.check(Level::Kv)?, + Base::Db => opt.check(Level::Ns)?, _ => unreachable!(), } // Continue @@ -369,12 +369,12 @@ impl DefineScopeStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -492,12 +492,12 @@ impl DefineTableStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -623,12 +623,12 @@ impl DefineEventStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -697,12 +697,12 @@ impl DefineFieldStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -836,12 +836,12 @@ impl DefineIndexStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } diff --git a/src/sql/statements/delete.rs b/src/sql/statements/delete.rs index 52211c66..ed99b20b 100644 --- a/src/sql/statements/delete.rs +++ b/src/sql/statements/delete.rs @@ -33,12 +33,12 @@ impl DeleteStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::No)?; + opt.check(Level::No)?; // Create a new iterator let mut i = Iterator::new(); // Pass in current statement diff --git a/src/sql/statements/ifelse.rs b/src/sql/statements/ifelse.rs index c2b1658d..efcdc12c 100644 --- a/src/sql/statements/ifelse.rs +++ b/src/sql/statements/ifelse.rs @@ -22,7 +22,7 @@ impl IfelseStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statements/info.rs b/src/sql/statements/info.rs index 734a2a5c..61908bda 100644 --- a/src/sql/statements/info.rs +++ b/src/sql/statements/info.rs @@ -24,16 +24,16 @@ impl InfoStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? match self { - InfoStatement::Namespace => exe.check(opt, Level::Ns)?, - InfoStatement::Database => exe.check(opt, Level::Db)?, - InfoStatement::Scope(_) => exe.check(opt, Level::Db)?, - InfoStatement::Table(_) => exe.check(opt, Level::Db)?, + InfoStatement::Namespace => opt.check(Level::Ns)?, + InfoStatement::Database => opt.check(Level::Db)?, + InfoStatement::Scope(_) => opt.check(Level::Db)?, + InfoStatement::Table(_) => opt.check(Level::Db)?, } // Continue todo!() diff --git a/src/sql/statements/insert.rs b/src/sql/statements/insert.rs index 7e4d2562..7b38980b 100644 --- a/src/sql/statements/insert.rs +++ b/src/sql/statements/insert.rs @@ -36,12 +36,12 @@ impl InsertStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::No)?; + opt.check(Level::No)?; // Create a new iterator let mut i = Iterator::new(); // Pass in current statement diff --git a/src/sql/statements/kill.rs b/src/sql/statements/kill.rs index 7774e417..81a2cdec 100644 --- a/src/sql/statements/kill.rs +++ b/src/sql/statements/kill.rs @@ -19,7 +19,7 @@ impl KillStatement { pub async fn compute( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statements/live.rs b/src/sql/statements/live.rs index 891d4362..fef1d775 100644 --- a/src/sql/statements/live.rs +++ b/src/sql/statements/live.rs @@ -29,7 +29,7 @@ impl LiveStatement { pub async fn compute( &self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statements/option.rs b/src/sql/statements/option.rs index 10fe167a..fb532f35 100644 --- a/src/sql/statements/option.rs +++ b/src/sql/statements/option.rs @@ -1,13 +1,7 @@ -use crate::dbs::Executor; -use crate::dbs::Level; -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::err::Error; use crate::sql::comment::mightbespace; use crate::sql::comment::shouldbespace; use crate::sql::error::IResult; use crate::sql::ident::{ident, Ident}; -use crate::sql::value::Value; use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; @@ -22,21 +16,6 @@ pub struct OptionStatement { pub what: bool, } -impl OptionStatement { - pub async fn compute( - &self, - _ctx: &Runtime, - opt: &Options<'_>, - exe: &Executor<'_>, - _doc: Option<&Value>, - ) -> Result { - // Allowed to run? - exe.check(opt, Level::Db)?; - // Return nothing - Ok(Value::None) - } -} - impl fmt::Display for OptionStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.what { diff --git a/src/sql/statements/output.rs b/src/sql/statements/output.rs index f45b6ace..47dd025e 100644 --- a/src/sql/statements/output.rs +++ b/src/sql/statements/output.rs @@ -18,7 +18,7 @@ impl OutputStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statements/relate.rs b/src/sql/statements/relate.rs index 68c41c82..71798746 100644 --- a/src/sql/statements/relate.rs +++ b/src/sql/statements/relate.rs @@ -39,12 +39,12 @@ impl RelateStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::No)?; + opt.check(Level::No)?; // Create a new iterator let mut i = Iterator::new(); // Pass in current statement diff --git a/src/sql/statements/remove.rs b/src/sql/statements/remove.rs index d8224858..a5d3d107 100644 --- a/src/sql/statements/remove.rs +++ b/src/sql/statements/remove.rs @@ -32,7 +32,7 @@ impl RemoveStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { @@ -93,12 +93,12 @@ impl RemoveNamespaceStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Kv)?; + opt.check(Level::Kv)?; // Continue todo!() } @@ -137,12 +137,12 @@ impl RemoveDatabaseStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Ns)?; + opt.check(Level::Ns)?; // Continue todo!() } @@ -182,14 +182,14 @@ impl RemoveLoginStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? match self.base { - Base::Ns => exe.check(opt, Level::Kv)?, - Base::Db => exe.check(opt, Level::Ns)?, + Base::Ns => opt.check(Level::Kv)?, + Base::Db => opt.check(Level::Ns)?, _ => unreachable!(), } // Continue @@ -236,14 +236,14 @@ impl RemoveTokenStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? match self.base { - Base::Ns => exe.check(opt, Level::Kv)?, - Base::Db => exe.check(opt, Level::Ns)?, + Base::Ns => opt.check(Level::Kv)?, + Base::Db => opt.check(Level::Ns)?, _ => unreachable!(), } // Continue @@ -289,12 +289,12 @@ impl RemoveScopeStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -333,12 +333,12 @@ impl RemoveTableStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -378,12 +378,12 @@ impl RemoveEventStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -429,12 +429,12 @@ impl RemoveFieldStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } @@ -480,12 +480,12 @@ impl RemoveIndexStatement { pub async fn compute( &self, _ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, _doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::Db)?; + opt.check(Level::Db)?; // Continue todo!() } diff --git a/src/sql/statements/select.rs b/src/sql/statements/select.rs index 05803ca1..447876e0 100644 --- a/src/sql/statements/select.rs +++ b/src/sql/statements/select.rs @@ -67,12 +67,12 @@ impl SelectStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::No)?; + opt.check(Level::No)?; // Create a new iterator let mut i = Iterator::new(); // Pass in current statement @@ -85,8 +85,6 @@ impl SelectStatement { i.start = self.start.as_ref(); // Ensure futures are processed let opt = &opt.futures(true); - // Specify the document version - let opt = &opt.version(self.version.as_ref()); // Loop over the select targets for w in self.what.0.iter() { let v = w.compute(ctx, opt, exe, doc).await?; diff --git a/src/sql/statements/set.rs b/src/sql/statements/set.rs index 4bfb25ff..bc8f3162 100644 --- a/src/sql/statements/set.rs +++ b/src/sql/statements/set.rs @@ -23,7 +23,7 @@ impl SetStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/statements/update.rs b/src/sql/statements/update.rs index e33d5a80..39b64b07 100644 --- a/src/sql/statements/update.rs +++ b/src/sql/statements/update.rs @@ -35,12 +35,12 @@ impl UpdateStatement { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { // Allowed to run? - exe.check(opt, Level::No)?; + opt.check(Level::No)?; // Create a new iterator let mut i = Iterator::new(); // Pass in current statement diff --git a/src/sql/statements/yuse.rs b/src/sql/statements/yuse.rs index cc3f605c..f2238635 100644 --- a/src/sql/statements/yuse.rs +++ b/src/sql/statements/yuse.rs @@ -20,45 +20,6 @@ pub struct UseStatement { pub db: Option, } -impl UseStatement { - pub async fn compute( - &self, - _ctx: &Runtime, - opt: &Options<'_>, - exe: &mut Executor<'_>, - _doc: Option<&Value>, - ) -> Result { - if let Some(ns) = &self.ns { - match opt.auth { - Auth::No => exe.ns = Some(ns.to_owned()), - Auth::Kv => exe.ns = Some(ns.to_owned()), - Auth::Ns(v) if v == ns => exe.ns = Some(ns.to_owned()), - _ => { - exe.ns = None; - return Err(Error::NsAuthenticationError { - ns: ns.to_owned(), - }); - } - } - } - if let Some(db) = &self.db { - match opt.auth { - Auth::No => exe.db = Some(db.to_owned()), - Auth::Kv => exe.db = Some(db.to_owned()), - Auth::Ns(_) => exe.db = Some(db.to_owned()), - Auth::Db(_, v) if v == db => exe.db = Some(db.to_owned()), - _ => { - exe.db = None; - return Err(Error::DbAuthenticationError { - db: db.to_owned(), - }); - } - } - } - Ok(Value::None) - } -} - impl fmt::Display for UseStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "USE")?; diff --git a/src/sql/subquery.rs b/src/sql/subquery.rs index 6c999e65..06bae300 100644 --- a/src/sql/subquery.rs +++ b/src/sql/subquery.rs @@ -42,7 +42,7 @@ impl Subquery { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&Value>, ) -> Result { diff --git a/src/sql/value/array.rs b/src/sql/value/array.rs index 5c2e5b1a..81e02caf 100644 --- a/src/sql/value/array.rs +++ b/src/sql/value/array.rs @@ -10,7 +10,7 @@ impl Value { pub async fn array( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, ) -> Result<(), Error> { diff --git a/src/sql/value/clear.rs b/src/sql/value/clear.rs index 9c34ebdc..4f265c4f 100644 --- a/src/sql/value/clear.rs +++ b/src/sql/value/clear.rs @@ -9,7 +9,7 @@ impl Value { pub async fn clear( &mut self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, ) -> Result<(), Error> { *self = Value::from(Object::default()); diff --git a/src/sql/value/decrement.rs b/src/sql/value/decrement.rs index fae75bdf..61d2df3b 100644 --- a/src/sql/value/decrement.rs +++ b/src/sql/value/decrement.rs @@ -10,7 +10,7 @@ impl Value { pub async fn decrement( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, val: Value, diff --git a/src/sql/value/def.rs b/src/sql/value/def.rs index f5629594..c1e52513 100644 --- a/src/sql/value/def.rs +++ b/src/sql/value/def.rs @@ -24,7 +24,7 @@ impl Value { pub async fn def( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, val: Option<&Thing>, ) -> Result<(), Error> { diff --git a/src/sql/value/del.rs b/src/sql/value/del.rs index abbab3aa..90c5d60e 100644 --- a/src/sql/value/del.rs +++ b/src/sql/value/del.rs @@ -15,7 +15,7 @@ impl Value { pub async fn del( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, ) -> Result<(), Error> { diff --git a/src/sql/value/first.rs b/src/sql/value/first.rs index 588c35b4..99a4947e 100644 --- a/src/sql/value/first.rs +++ b/src/sql/value/first.rs @@ -10,7 +10,7 @@ impl Value { pub async fn first( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ) -> Result { self.get(ctx, opt, exe, &Idiom::from(vec![Part::First])).await diff --git a/src/sql/value/get.rs b/src/sql/value/get.rs index 18368809..bfe21f72 100644 --- a/src/sql/value/get.rs +++ b/src/sql/value/get.rs @@ -15,7 +15,7 @@ impl Value { pub async fn get( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, ) -> Result { diff --git a/src/sql/value/increment.rs b/src/sql/value/increment.rs index 508ad5d5..889635ab 100644 --- a/src/sql/value/increment.rs +++ b/src/sql/value/increment.rs @@ -10,7 +10,7 @@ impl Value { pub async fn increment( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, val: Value, diff --git a/src/sql/value/last.rs b/src/sql/value/last.rs index fe46cb40..ea4197e5 100644 --- a/src/sql/value/last.rs +++ b/src/sql/value/last.rs @@ -10,7 +10,7 @@ impl Value { pub async fn last( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, ) -> Result { self.get(ctx, opt, exe, &Idiom::from(vec![Part::Last])).await diff --git a/src/sql/value/merge.rs b/src/sql/value/merge.rs index 3c9c10a0..4541dab5 100644 --- a/src/sql/value/merge.rs +++ b/src/sql/value/merge.rs @@ -9,7 +9,7 @@ impl Value { pub async fn merge( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, val: &Object, ) -> Result<(), Error> { diff --git a/src/sql/value/object.rs b/src/sql/value/object.rs index 760f8877..e3cd3a7d 100644 --- a/src/sql/value/object.rs +++ b/src/sql/value/object.rs @@ -10,7 +10,7 @@ impl Value { pub async fn object( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, ) -> Result<(), Error> { diff --git a/src/sql/value/patch.rs b/src/sql/value/patch.rs index f56249e3..85e9d4dc 100644 --- a/src/sql/value/patch.rs +++ b/src/sql/value/patch.rs @@ -10,7 +10,7 @@ impl Value { pub async fn patch( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, val: &Array, ) -> Result<(), Error> { diff --git a/src/sql/value/replace.rs b/src/sql/value/replace.rs index 05569596..87f5bf76 100644 --- a/src/sql/value/replace.rs +++ b/src/sql/value/replace.rs @@ -9,7 +9,7 @@ impl Value { pub async fn replace( &mut self, _ctx: &Runtime, - _opt: &Options<'_>, + _opt: &Options, _exe: &Executor<'_>, val: &Object, ) -> Result<(), Error> { diff --git a/src/sql/value/set.rs b/src/sql/value/set.rs index 1676653e..751d1f8a 100644 --- a/src/sql/value/set.rs +++ b/src/sql/value/set.rs @@ -14,7 +14,7 @@ impl Value { pub async fn set( &mut self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, path: &Idiom, val: Value, diff --git a/src/sql/value/value.rs b/src/sql/value/value.rs index 43ff1137..2da461b2 100644 --- a/src/sql/value/value.rs +++ b/src/sql/value/value.rs @@ -793,7 +793,7 @@ impl Value { pub async fn compute( &self, ctx: &Runtime, - opt: &Options<'_>, + opt: &Options, exe: &Executor<'_>, doc: Option<&'async_recursion Value>, ) -> Result {