#[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,
},
Rel {
quant: Quant,
rel: RelRef,
cond: Box<Cond>,
},
}
impl Cond {
pub fn is_always_true(&self) -> bool {
match self {
Cond::True => true,
Cond::False => false,
Cond::And(items) => items.iter().all(Cond::is_always_true),
Cond::Or(items) => items.iter().any(Cond::is_always_true),
Cond::Not(inner) => inner.is_always_false(),
_ => false,
}
}
pub fn is_always_false(&self) -> bool {
match self {
Cond::False => true,
Cond::True => false,
Cond::And(items) => items.iter().any(Cond::is_always_false),
Cond::Or(items) => items.iter().all(Cond::is_always_false),
Cond::Not(inner) => inner.is_always_true(),
_ => false,
}
}
}
#[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 physical: String,
}
impl FieldRef {
pub fn identity(name: impl Into<String>) -> Self {
FieldRef {
physical: name.into(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(String),
}