diff --git a/lib/src/sql/graph.rs b/lib/src/sql/graph.rs index 14a8748d..39e21adc 100644 --- a/lib/src/sql/graph.rs +++ b/lib/src/sql/graph.rs @@ -7,6 +7,7 @@ use crate::sql::value::{value, Value}; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::character::complete::char; +use nom::combinator::map; use nom::combinator::opt; use serde::{Deserialize, Serialize}; use std::fmt; @@ -44,10 +45,18 @@ pub struct Graph { impl fmt::Display for Graph { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.what.0.len() == 1 && self.cond.is_none() && self.alias.is_none() { - write!(f, "{}{}", self.dir, self.what) + if self.what.0.len() <= 1 && self.cond.is_none() && self.alias.is_none() { + write!(f, "{}", self.dir,)?; + match self.what.len() { + 0 => write!(f, "?"), + _ => write!(f, "{}", self.what), + } } else { - write!(f, "{}({}", self.dir, self.what)?; + write!(f, "{}(", self.dir,)?; + match self.what.len() { + 0 => write!(f, "?"), + _ => write!(f, "{}", self.what), + }?; if let Some(ref v) = self.cond { write!(f, " WHERE {}", v)? } @@ -126,10 +135,14 @@ fn custom(i: &str) -> IResult<&str, (Tables, Option, Option)> { } fn what(i: &str) -> IResult<&str, Tables> { - let (i, v) = tables(i)?; + let (i, v) = alt((any, tables))(i)?; Ok((i, v)) } +fn any(i: &str) -> IResult<&str, Tables> { + map(char('?'), |_| Tables::default())(i) +} + fn cond(i: &str) -> IResult<&str, Value> { let (i, _) = shouldbespace(i)?; let (i, _) = tag_no_case("WHERE")(i)?; diff --git a/lib/src/sql/table.rs b/lib/src/sql/table.rs index 55921e11..c75aa13a 100644 --- a/lib/src/sql/table.rs +++ b/lib/src/sql/table.rs @@ -13,6 +13,13 @@ use std::str; #[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] pub struct Tables(pub Vec); +impl Deref for Tables { + type Target = Vec
; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl fmt::Display for Tables { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0.iter().map(|ref v| format!("{}", v)).collect::>().join(", "))