Change method argument names
This commit is contained in:
parent
8a08de951e
commit
222e417c79
4 changed files with 75 additions and 82 deletions
|
@ -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
|
||||
|
|
|
@ -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<Error>,
|
||||
pub(super) txn: Option<Transaction>,
|
||||
kvs: Store,
|
||||
err: Option<Error>,
|
||||
txn: Option<Transaction>,
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ mod auth;
|
|||
mod channel;
|
||||
mod dbs;
|
||||
mod executor;
|
||||
mod export;
|
||||
mod iterate;
|
||||
mod iterator;
|
||||
mod options;
|
||||
|
|
Loading…
Reference in a new issue