#[derive(Debug, Clone, PartialEq)]
pub enum Cond {
True,
False,
And(Vec<Cond>),
Or(Vec<Cond>),
Not(Box<Cond>),
Compare {
field: FieldRef,
op: CmpOp,
value: Value,
},
In {
field: FieldRef,
values: Vec<Value>,
negated: bool,
},
IsNull {
field: FieldRef,
negated: bool,
},
Between {
field: FieldRef,
low: Value,
high: Value,
low_incl: bool,
high_incl: bool,
negated: bool,
},
Text {
field: FieldRef,
op: TextOp,
pattern: String,
ci: bool,
},
Rel {
quant: Quant,
rel: RelRef,
cond: Box<Cond>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Quant {
Any,
All,
None,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RelRef {
pub name: String,
pub target_table: String,
pub local: String,
pub foreign: String,
pub through: Option<JunctionRef>,
pub mongo: MongoStorage,
pub es: EsStorage,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum MongoStorage {
#[default]
Embedded,
Referenced,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum EsStorage {
#[default]
Nested,
Child,
}
#[derive(Debug, Clone, PartialEq)]
pub struct JunctionRef {
pub table: String,
pub local: String,
pub foreign: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmpOp {
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
}
impl CmpOp {
pub fn flipped(self) -> Self {
match self {
CmpOp::Eq => CmpOp::Eq,
CmpOp::Ne => CmpOp::Ne,
CmpOp::Lt => CmpOp::Gt,
CmpOp::Le => CmpOp::Ge,
CmpOp::Gt => CmpOp::Lt,
CmpOp::Ge => CmpOp::Le,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextOp {
StartsWith,
EndsWith,
Contains,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FieldRef {
pub path: Vec<String>,
pub physical: String,
pub ty: FieldType,
}
impl FieldRef {
pub fn identity(name: impl Into<String>) -> Self {
let name = name.into();
FieldRef {
path: vec![name.clone()],
physical: name,
ty: FieldType::Unknown,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum FieldType {
Bool,
Int,
Float,
Decimal,
Text,
Keyword,
Date,
Timestamp,
Json,
#[default]
Unknown,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(String),
List(Vec<Value>),
}