diff --git a/lib/src/dbs/executor.rs b/lib/src/dbs/executor.rs index 5a93da99..b59aa03b 100644 --- a/lib/src/dbs/executor.rs +++ b/lib/src/dbs/executor.rs @@ -126,7 +126,7 @@ impl<'a> Executor<'a> { // Initialise array of responses let mut out: Vec = vec![]; // Process all statements in query - for stm in qry.statements().iter() { + for stm in qry.iter() { // Log the statement debug!("Executing: {}", stm); // Reset errors diff --git a/lib/src/sql/query.rs b/lib/src/sql/query.rs index ba87f99e..7819a943 100644 --- a/lib/src/sql/query.rs +++ b/lib/src/sql/query.rs @@ -3,33 +3,28 @@ use crate::sql::statement::{statements, Statement, Statements}; use nom::combinator::all_consuming; use serde::{Deserialize, Serialize}; use std::fmt; +use std::ops::Deref; use std::str; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] -pub struct Query { - pub statements: Statements, -} +pub struct Query(pub Statements); -impl Query { - pub fn statements(&self) -> &Vec { - &self.statements.0 +impl Deref for Query { + type Target = Vec; + fn deref(&self) -> &Self::Target { + &self.0 .0 } } impl fmt::Display for Query { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.statements) + write!(f, "{}", self.0) } } pub fn query(i: &str) -> IResult<&str, Query> { let (i, v) = all_consuming(statements)(i)?; - Ok(( - i, - Query { - statements: v, - }, - )) + Ok((i, Query(v))) } #[cfg(test)] diff --git a/lib/src/sql/statement.rs b/lib/src/sql/statement.rs index 4a8d2f1f..1c43f435 100644 --- a/lib/src/sql/statement.rs +++ b/lib/src/sql/statement.rs @@ -32,12 +32,20 @@ use nom::multi::separated_list1; use nom::sequence::delimited; use serde::{Deserialize, Serialize}; use std::fmt; +use std::ops::Deref; use std::sync::Arc; use std::time::Duration; #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct Statements(pub Vec); +impl Deref for Statements { + type Target = Vec; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl fmt::Display for Statements { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0.iter().map(|ref v| format!("{};", v)).collect::>().join("\n"))