diff --git a/src/dbs/dbs.rs b/src/dbs/dbs.rs index 43387caf..20ab876a 100644 --- a/src/dbs/dbs.rs +++ b/src/dbs/dbs.rs @@ -12,7 +12,7 @@ use hyper::body::Sender; use std::sync::Arc; pub async fn execute( - db: Store, + kvs: Store, txt: &str, session: Session, vars: Variables, @@ -20,7 +20,7 @@ pub async fn execute( // Create a new query options let mut opt = Options::default(); // Create a new query executor - let mut exe = Executor::new(db); + let mut exe = Executor::new(kvs); // Create a new execution context let ctx = session.context(); // Attach the defined variables @@ -35,7 +35,7 @@ pub async fn execute( } pub async fn process( - db: Store, + kvs: Store, ast: Query, session: Session, vars: Variables, @@ -43,7 +43,7 @@ pub async fn process( // Create a new query options let mut opt = Options::default(); // Create a new query executor - let mut exe = Executor::new(db); + let mut exe = Executor::new(kvs); // Store session info on context let ctx = session.context(); // Attach the defined variables @@ -55,11 +55,11 @@ pub async fn process( exe.execute(ctx, opt, ast).await } -pub async fn export(db: Store, session: Session, sender: Sender) -> Result<(), Error> { +pub async fn export(kvs: Store, session: Session, sender: Sender) -> Result<(), Error> { // Create a new query options let mut opt = Options::default(); // Create a new query executor - let mut exe = Executor::new(db); + let mut exe = Executor::new(kvs); // Create a new execution context let ctx = session.context(); // Process database export diff --git a/src/dbs/executor.rs b/src/dbs/executor.rs index 20bada31..0100e1f0 100644 --- a/src/dbs/executor.rs +++ b/src/dbs/executor.rs @@ -10,19 +10,20 @@ use crate::sql::query::Query; use crate::sql::statement::Statement; use crate::sql::value::Value; use futures::lock::Mutex; +use hyper::body::Sender; use std::sync::Arc; use std::time::Instant; pub struct Executor { - pub(super) dbs: Store, - pub(super) err: Option, - pub(super) txn: Option, + kvs: Store, + err: Option, + txn: Option, } impl Executor { - pub fn new(dbs: Store) -> Executor { + pub fn new(kvs: Store) -> Executor { Executor { - dbs, + kvs, txn: None, err: None, } @@ -38,7 +39,7 @@ impl Executor { async fn begin(&mut self) -> bool { match self.txn.as_ref() { Some(_) => false, - None => match self.dbs.transaction(true, false).await { + None => match self.kvs.transaction(true, false).await { Ok(v) => { self.txn = Some(Arc::new(Mutex::new(v))); true @@ -303,4 +304,66 @@ impl Executor { // Return responses Ok(Responses(out)) } + + pub async fn export( + &mut self, + ctx: Runtime, + opt: Options, + mut chn: Sender, + ) -> Result<(), Error> { + // Start a new transaction + let txn = self.kvs.transaction(false, false).await?; + // Output OPTIONS + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("-- OPTION")).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + chn.send_data(output!("OPTION IMPORT;")).await?; + chn.send_data(output!("")).await?; + // Output LOGINS + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("-- LOGINS")).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + // Output TOKENS + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("-- TOKENS")).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + // Output SCOPES + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("-- SCOPES")).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + // Output TABLES + for v in 0..1 { + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!(format!("-- TABLE: {}", v))).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + } + // Start transaction + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("-- TRANSACTION")).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + chn.send_data(output!("BEGIN TRANSACTION;")).await?; + chn.send_data(output!("")).await?; + // Output TABLE data + for v in 0..1 { + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!(format!("-- TABLE DATA: {}", v))).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + } + // Commit transaction + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("-- TRANSACTION")).await?; + chn.send_data(output!("-- ------------------------------")).await?; + chn.send_data(output!("")).await?; + chn.send_data(output!("COMMIT TRANSACTION;")).await?; + chn.send_data(output!("")).await?; + // Everything ok + Ok(()) + } } diff --git a/src/dbs/export.rs b/src/dbs/export.rs deleted file mode 100644 index 346c3fda..00000000 --- a/src/dbs/export.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::dbs::Executor; -use crate::dbs::Options; -use crate::dbs::Runtime; -use crate::err::Error; -use hyper::body::Sender; - -impl Executor { - pub async fn export( - &mut self, - ctx: Runtime, - opt: Options, - mut chn: Sender, - ) -> Result<(), Error> { - // Start a new transaction - let txn = self.dbs.transaction(false, false).await?; - // Output OPTIONS - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("-- OPTION")).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - chn.send_data(output!("OPTION IMPORT;")).await?; - chn.send_data(output!("")).await?; - // Output LOGINS - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("-- LOGINS")).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - // Output TOKENS - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("-- TOKENS")).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - // Output SCOPES - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("-- SCOPES")).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - // Output TABLES - for v in 0..1 { - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!(format!("-- TABLE: {}", v))).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - } - // Start transaction - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("-- TRANSACTION")).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - chn.send_data(output!("BEGIN TRANSACTION;")).await?; - chn.send_data(output!("")).await?; - // Output TABLE data - for v in 0..1 { - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!(format!("-- TABLE DATA: {}", v))).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - } - // Commit transaction - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("-- TRANSACTION")).await?; - chn.send_data(output!("-- ------------------------------")).await?; - chn.send_data(output!("")).await?; - chn.send_data(output!("COMMIT TRANSACTION;")).await?; - chn.send_data(output!("")).await?; - // Everything ok - Ok(()) - } -} diff --git a/src/dbs/mod.rs b/src/dbs/mod.rs index 17e6e13e..8b99ae63 100644 --- a/src/dbs/mod.rs +++ b/src/dbs/mod.rs @@ -2,7 +2,6 @@ mod auth; mod channel; mod dbs; mod executor; -mod export; mod iterate; mod iterator; mod options;