Enable ? operator in graph traversal queries
This commit is contained in:
parent
4d9b3fd403
commit
bea90712a3
2 changed files with 24 additions and 4 deletions
|
@ -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<Value>, Option<Idiom>)> {
|
|||
}
|
||||
|
||||
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)?;
|
||||
|
|
|
@ -13,6 +13,13 @@ use std::str;
|
|||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Tables(pub Vec<Table>);
|
||||
|
||||
impl Deref for Tables {
|
||||
type Target = Vec<Table>;
|
||||
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::<Vec<_>>().join(", "))
|
||||
|
|
Loading…
Reference in a new issue