Skip to main content

cratestack_sql/filter/
filter.rs

1use crate::{IntoSqlValue, SqlValue, values::FilterValue};
2
3use super::op::FilterOp;
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct Filter {
7    pub column: &'static str,
8    pub op: FilterOp,
9    pub value: FilterValue,
10}
11
12impl Filter {
13    pub(super) fn single<V>(column: &'static str, op: FilterOp, value: V) -> Self
14    where
15        V: IntoSqlValue,
16    {
17        Self {
18            column,
19            op,
20            value: FilterValue::Single(value.into_sql_value()),
21        }
22    }
23
24    pub(super) fn string_pattern(
25        column: &'static str,
26        op: FilterOp,
27        pattern: &str,
28        value: impl Into<String>,
29    ) -> Self {
30        Self {
31            column,
32            op,
33            value: FilterValue::Single(SqlValue::String(pattern.replacen("{}", &value.into(), 1))),
34        }
35    }
36}