Skip to main content

sql_orm_query/
predicate.rs

1use crate::expr::Expr;
2
3#[derive(Debug, Clone, PartialEq)]
4pub enum Predicate {
5    Eq(Expr, Expr),
6    Ne(Expr, Expr),
7    Gt(Expr, Expr),
8    Gte(Expr, Expr),
9    Lt(Expr, Expr),
10    Lte(Expr, Expr),
11    Like(Expr, Expr),
12    LikeEscaped(Expr, Expr, char),
13    IsNull(Expr),
14    IsNotNull(Expr),
15    And(Vec<Predicate>),
16    Or(Vec<Predicate>),
17    Not(Box<Predicate>),
18}
19
20impl Predicate {
21    pub const fn eq(left: Expr, right: Expr) -> Self {
22        Self::Eq(left, right)
23    }
24
25    pub const fn ne(left: Expr, right: Expr) -> Self {
26        Self::Ne(left, right)
27    }
28
29    pub const fn gt(left: Expr, right: Expr) -> Self {
30        Self::Gt(left, right)
31    }
32
33    pub const fn gte(left: Expr, right: Expr) -> Self {
34        Self::Gte(left, right)
35    }
36
37    pub const fn lt(left: Expr, right: Expr) -> Self {
38        Self::Lt(left, right)
39    }
40
41    pub const fn lte(left: Expr, right: Expr) -> Self {
42        Self::Lte(left, right)
43    }
44
45    pub const fn like(left: Expr, right: Expr) -> Self {
46        Self::Like(left, right)
47    }
48
49    pub const fn like_escaped(left: Expr, right: Expr, escape: char) -> Self {
50        Self::LikeEscaped(left, right, escape)
51    }
52
53    pub const fn is_null(expr: Expr) -> Self {
54        Self::IsNull(expr)
55    }
56
57    pub const fn is_not_null(expr: Expr) -> Self {
58        Self::IsNotNull(expr)
59    }
60
61    pub fn and(predicates: Vec<Predicate>) -> Self {
62        Self::And(predicates)
63    }
64
65    pub fn or(predicates: Vec<Predicate>) -> Self {
66        Self::Or(predicates)
67    }
68
69    pub fn negate(predicate: Predicate) -> Self {
70        Self::Not(Box::new(predicate))
71    }
72}