sql_orm_query/
predicate.rs1use 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 IsNull(Expr),
13 IsNotNull(Expr),
14 And(Vec<Predicate>),
15 Or(Vec<Predicate>),
16 Not(Box<Predicate>),
17}
18
19impl Predicate {
20 pub const fn eq(left: Expr, right: Expr) -> Self {
21 Self::Eq(left, right)
22 }
23
24 pub const fn ne(left: Expr, right: Expr) -> Self {
25 Self::Ne(left, right)
26 }
27
28 pub const fn gt(left: Expr, right: Expr) -> Self {
29 Self::Gt(left, right)
30 }
31
32 pub const fn gte(left: Expr, right: Expr) -> Self {
33 Self::Gte(left, right)
34 }
35
36 pub const fn lt(left: Expr, right: Expr) -> Self {
37 Self::Lt(left, right)
38 }
39
40 pub const fn lte(left: Expr, right: Expr) -> Self {
41 Self::Lte(left, right)
42 }
43
44 pub const fn like(left: Expr, right: Expr) -> Self {
45 Self::Like(left, right)
46 }
47
48 pub const fn is_null(expr: Expr) -> Self {
49 Self::IsNull(expr)
50 }
51
52 pub const fn is_not_null(expr: Expr) -> Self {
53 Self::IsNotNull(expr)
54 }
55
56 pub fn and(predicates: Vec<Predicate>) -> Self {
57 Self::And(predicates)
58 }
59
60 pub fn or(predicates: Vec<Predicate>) -> Self {
61 Self::Or(predicates)
62 }
63
64 pub fn negate(predicate: Predicate) -> Self {
65 Self::Not(Box::new(predicate))
66 }
67}