| |
|
|
| use std::fmt; |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub struct ParsedQuery { |
| pub from: ParsedFromClause, |
| pub operations: Vec<ParsedOperation>, |
| pub aggregation: Option<ParsedAggregation>, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub struct ParsedFromClause { |
| pub selector: ParsedEntitySelector, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum ParsedEntitySelector { |
| Type(String), |
| Wildcard, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum ParsedOperation { |
| Where(ParsedCompoundCondition), |
| Related { |
| degree: Option<usize>, |
| selector: Option<ParsedEntitySelector>, |
| }, |
| Order { |
| field: ParsedField, |
| direction: ParsedDirection, |
| }, |
| Limit(usize), |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum ParsedAggregation { |
| |
| Select(Vec<ParsedField>), |
| |
| Count(Option<ParsedField>), |
| |
| Sum(ParsedField), |
| |
| Average(ParsedField), |
| |
| Median(ParsedField), |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub struct ParsedCompoundCondition { |
| pub conditions: Vec<ParsedCondition>, |
| pub combinator: ParsedCombinator, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq, Default)] |
| pub enum ParsedCombinator { |
| #[default] |
| And, |
| Or, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub struct ParsedCondition { |
| pub field: ParsedField, |
| pub operator: ParsedOperator, |
| pub value: ParsedQueryValue, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum ParsedField { |
| Metadata(String), |
| Regular(String), |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum ParsedOperator { |
| Equal, |
| NotEqual, |
| GreaterThan, |
| LessThan, |
| GreaterOrEqual, |
| LessOrEqual, |
| Contains, |
| StartsWith, |
| EndsWith, |
| In, |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| pub enum ParsedQueryValue { |
| String(String), |
| Number(f64), |
| Boolean(bool), |
| Currency { amount: f64, code: String }, |
| DateTime(String), |
| Reference(String), |
| Path(String), |
| Enum(String), |
| List(Vec<ParsedQueryValue>), |
| } |
|
|
| |
| #[derive(Debug, Clone, PartialEq)] |
| #[derive(Default)] |
| pub enum ParsedDirection { |
| #[default] |
| Ascending, |
| Descending, |
| } |
|
|
|
|
| impl fmt::Display for ParsedEntitySelector { |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| match self { |
| ParsedEntitySelector::Type(t) => write!(f, "{}", t), |
| ParsedEntitySelector::Wildcard => write!(f, "*"), |
| } |
| } |
| } |
|
|
| impl fmt::Display for ParsedOperator { |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| match self { |
| ParsedOperator::Equal => write!(f, "=="), |
| ParsedOperator::NotEqual => write!(f, "!="), |
| ParsedOperator::GreaterThan => write!(f, ">"), |
| ParsedOperator::LessThan => write!(f, "<"), |
| ParsedOperator::GreaterOrEqual => write!(f, ">="), |
| ParsedOperator::LessOrEqual => write!(f, "<="), |
| ParsedOperator::Contains => write!(f, "contains"), |
| ParsedOperator::StartsWith => write!(f, "startswith"), |
| ParsedOperator::EndsWith => write!(f, "endswith"), |
| ParsedOperator::In => write!(f, "in"), |
| } |
| } |
| } |
|
|
| impl fmt::Display for ParsedDirection { |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| match self { |
| ParsedDirection::Ascending => write!(f, "asc"), |
| ParsedDirection::Descending => write!(f, "desc"), |
| } |
| } |
| } |
|
|