Change method argument names

This commit is contained in:
Tobie Morgan Hitchcock 2022-02-19 23:09:23 +00:00
parent 8a08de951e
commit 222e417c79
4 changed files with 75 additions and 82 deletions

View file

@ -12,7 +12,7 @@ use hyper::body::Sender;
use std::sync::Arc; use std::sync::Arc;
pub async fn execute( pub async fn execute(
db: Store, kvs: Store,
txt: &str, txt: &str,
session: Session, session: Session,
vars: Variables, vars: Variables,
@ -20,7 +20,7 @@ pub async fn execute(
// Create a new query options // Create a new query options
let mut opt = Options::default(); let mut opt = Options::default();
// Create a new query executor // Create a new query executor
let mut exe = Executor::new(db); let mut exe = Executor::new(kvs);
// Create a new execution context // Create a new execution context
let ctx = session.context(); let ctx = session.context();
// Attach the defined variables // Attach the defined variables
@ -35,7 +35,7 @@ pub async fn execute(
} }
pub async fn process( pub async fn process(
db: Store, kvs: Store,
ast: Query, ast: Query,
session: Session, session: Session,
vars: Variables, vars: Variables,
@ -43,7 +43,7 @@ pub async fn process(
// Create a new query options // Create a new query options
let mut opt = Options::default(); let mut opt = Options::default();
// Create a new query executor // Create a new query executor
let mut exe = Executor::new(db); let mut exe = Executor::new(kvs);
// Store session info on context // Store session info on context
let ctx = session.context(); let ctx = session.context();
// Attach the defined variables // Attach the defined variables
@ -55,11 +55,11 @@ pub async fn process(
exe.execute(ctx, opt, ast).await 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 // Create a new query options
let mut opt = Options::default(); let mut opt = Options::default();
// Create a new query executor // Create a new query executor
let mut exe = Executor::new(db); let mut exe = Executor::new(kvs);
// Create a new execution context // Create a new execution context
let ctx = session.context(); let ctx = session.context();
// Process database export // Process database export

View file

@ -10,19 +10,20 @@ use crate::sql::query::Query;
use crate::sql::statement::Statement; use crate::sql::statement::Statement;
use crate::sql::value::Value; use crate::sql::value::Value;
use futures::lock::Mutex; use futures::lock::Mutex;
use hyper::body::Sender;
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant; use std::time::Instant;
pub struct Executor { pub struct Executor {
pub(super) dbs: Store, kvs: Store,
pub(super) err: Option<Error>, err: Option<Error>,
pub(super) txn: Option<Transaction>, txn: Option<Transaction>,
} }
impl Executor { impl Executor {
pub fn new(dbs: Store) -> Executor { pub fn new(kvs: Store) -> Executor {
Executor { Executor {
dbs, kvs,
txn: None, txn: None,
err: None, err: None,
} }
@ -38,7 +39,7 @@ impl Executor {
async fn begin(&mut self) -> bool { async fn begin(&mut self) -> bool {
match self.txn.as_ref() { match self.txn.as_ref() {
Some(_) => false, Some(_) => false,
None => match self.dbs.transaction(true, false).await { None => match self.kvs.transaction(true, false).await {
Ok(v) => { Ok(v) => {
self.txn = Some(Arc::new(Mutex::new(v))); self.txn = Some(Arc::new(Mutex::new(v)));
true true
@ -303,4 +304,66 @@ impl Executor {
// Return responses // Return responses
Ok(Responses(out)) 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(())
}
} }

View file

@ -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(())
}
}

View file

@ -2,7 +2,6 @@ mod auth;
mod channel; mod channel;
mod dbs; mod dbs;
mod executor; mod executor;
mod export;
mod iterate; mod iterate;
mod iterator; mod iterator;
mod options; mod options;