feat: handle comparisons =, >, <, >=, <= for condition real

This commit is contained in:
2025-10-20 08:26:23 +02:00
parent bc9aee953c
commit 81bed07665
5 changed files with 475 additions and 2 deletions

View File

@@ -26,6 +26,15 @@ pub fn run<'a>(filter: &'a Filter) -> Result<Vec<Box<dyn ToSql + 'a>>, FailedTo>
| Comparison::LesserOrEqual,
Condition::UnsignedInt(value),
) => params.push(Box::new(value)),
// REAL
(
Comparison::Equal
| Comparison::Greater
| Comparison::Lesser
| Comparison::GreaterOrEqual
| Comparison::LesserOrEqual,
Condition::Real(value),
) => params.push(Box::new(value)),
// TEXT
(Comparison::IsExactly, Condition::Text(value)) => params.push(Box::new(value)),
(Comparison::StartsWith, Condition::Text(value)) => {

View File

@@ -59,6 +59,23 @@ pub fn run(filter: &Filter) -> Result<String, FailedTo> {
compose_fragment(name, "value_uint", "<=", i + 1)
}
(_, Condition::UnsignedInt(_)) => return Err(FailedTo::ComposeFilter),
// REAL
(Comparison::Equal, Condition::Real(_)) => {
compose_fragment(name, "value_real", "=", i + 1)
}
(Comparison::Greater, Condition::Real(_)) => {
compose_fragment(name, "value_real", ">", i + 1)
}
(Comparison::Lesser, Condition::Real(_)) => {
compose_fragment(name, "value_real", "<", i + 1)
}
(Comparison::GreaterOrEqual, Condition::Real(_)) => {
compose_fragment(name, "value_real", ">=", i + 1)
}
(Comparison::LesserOrEqual, Condition::Real(_)) => {
compose_fragment(name, "value_real", "<=", i + 1)
}
(_, Condition::Real(_)) => return Err(FailedTo::ComposeFilter),
// TEXT
(Comparison::IsExactly, Condition::Text(_)) => {
compose_fragment(name, "value_text", "LIKE", i + 1)

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,8 @@
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Hash)]
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
pub enum E<'a> {
Bool(bool),
Real(f64),
SignedInt(i64),
UnsignedInt(i64),
Text(&'a str),
UnsignedInt(i64),
}

View File

@@ -58,6 +58,14 @@ impl<'a> Filter<'a> {
));
self
}
pub fn with_real(mut self, attribute_name: &str, comparison: Comparison, value: f64) -> Self {
self.conditions.push((
attribute_name.to_string(),
comparison,
Condition::Real(value),
));
self
}
pub(crate) fn conditions(&self) -> impl Iterator<Item = &(String, Comparison, Condition<'a>)> {
self.conditions.iter()
}