feat: handle comparisons =, >, <, >=, <= for condition real
This commit is contained in:
@@ -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)) => {
|
||||
|
||||
@@ -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
@@ -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),
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user