#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ComparisonOperator {
Eq,
Ne,
Gt,
Gte,
Lt,
Lte,
}
#[derive(Debug, Clone)]
pub enum FieldRef {
Field {
table_alias: Option<String>,
field_path: Vec<String>,
},
Value(String),
}
impl FieldRef {
pub fn field(field_path: Vec<String>) -> Self {
Self::Field {
table_alias: None,
field_path,
}
}
pub fn field_with_alias(table_alias: String, field_path: Vec<String>) -> Self {
Self::Field {
table_alias: Some(table_alias),
field_path,
}
}
pub fn value(value: String) -> Self {
Self::Value(value)
}
pub fn with_alias(mut self, alias: &str) -> Self {
if let Self::Field {
ref mut table_alias,
..
} = self
{
*table_alias = Some(alias.to_string());
}
self
}
}
#[derive(Debug, Clone)]
pub struct FieldComparison {
pub left: FieldRef,
pub right: FieldRef,
pub op: ComparisonOperator,
}
impl FieldComparison {
pub fn new(left: FieldRef, right: FieldRef, op: ComparisonOperator) -> Self {
Self { left, right, op }
}
}