icydb_core/db/query/predicate/
ast.rs1use crate::value::Value;
2
3use super::coercion::CoercionSpec;
4use std::ops::BitAnd;
5
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
24pub enum CompareOp {
25 Eq,
26 Ne,
27 Lt,
28 Lte,
29 Gt,
30 Gte,
31 In,
32 NotIn,
33 AnyIn,
34 AllIn,
35 Contains,
36 StartsWith,
37 EndsWith,
38}
39
40#[derive(Clone, Debug, Eq, PartialEq)]
45pub struct ComparePredicate {
46 pub field: String,
47 pub op: CompareOp,
48 pub value: Value,
49 pub coercion: CoercionSpec,
50}
51
52#[derive(Clone, Debug, Eq, PartialEq)]
57pub enum Predicate {
58 True,
59 False,
60 And(Vec<Self>),
61 Or(Vec<Self>),
62 Not(Box<Self>),
63 Compare(ComparePredicate),
64 IsNull {
65 field: String,
66 },
67 IsMissing {
68 field: String,
69 },
70 IsEmpty {
71 field: String,
72 },
73 IsNotEmpty {
74 field: String,
75 },
76 MapContainsKey {
77 field: String,
78 key: Value,
79 coercion: CoercionSpec,
80 },
81 MapContainsValue {
82 field: String,
83 value: Value,
84 coercion: CoercionSpec,
85 },
86 MapContainsEntry {
87 field: String,
88 key: Value,
89 value: Value,
90 coercion: CoercionSpec,
91 },
92 TextContains {
93 field: String,
94 value: Value,
95 },
96 TextContainsCi {
97 field: String,
98 value: Value,
99 },
100}
101
102impl BitAnd for Predicate {
103 type Output = Self;
104
105 fn bitand(self, rhs: Self) -> Self::Output {
106 Self::And(vec![self, rhs])
107 }
108}
109
110impl BitAnd for &Predicate {
111 type Output = Predicate;
112
113 fn bitand(self, rhs: Self) -> Self::Output {
114 Predicate::And(vec![self.clone(), rhs.clone()])
115 }
116}