shared/domain/ports/query/
builder.rs1use super::value::{DbValue, Op, Operation};
2
3#[derive(Clone, Debug)]
4pub struct QueryBuilder {
5 pub filters: Vec<Operation>,
6 pub updates: Vec<Operation>,
7}
8
9impl Default for QueryBuilder {
10 fn default() -> Self {
11 Self::new()
12 }
13}
14
15impl QueryBuilder {
16 pub fn new() -> Self {
17 Self {
18 filters: vec![],
19 updates: vec![],
20 }
21 }
22
23 pub fn ne(mut self, field: &'static str, value: impl Into<DbValue>) -> Self {
24 self.filters.push(Operation {
25 field,
26 op: Op::Ne,
27 value: value.into(),
28 });
29 self
30 }
31
32 pub fn eq(mut self, field: &'static str, value: impl Into<DbValue>) -> Self {
33 self.filters.push(Operation {
34 field,
35 op: Op::Eq,
36 value: value.into(),
37 });
38 self
39 }
40
41 pub fn in_(mut self, field: &'static str, value: impl Into<DbValue>) -> Self {
42 self.filters.push(Operation {
43 field,
44 op: Op::In,
45 value: value.into(),
46 });
47 self
48 }
49
50 pub fn gt(mut self, field: &'static str, value: impl Into<DbValue>) -> Self {
51 self.filters.push(Operation {
52 field,
53 op: Op::Gt,
54 value: value.into(),
55 });
56 self
57 }
58
59 pub fn set(mut self, field: &'static str, value: impl Into<DbValue>) -> Self {
60 self.updates.push(Operation {
61 field,
62 op: Op::Set,
63 value: value.into(),
64 });
65 self
66 }
67
68 pub fn is_null(mut self, field: &'static str) -> Self {
69 self.filters.push(Operation {
70 field,
71 op: Op::Null,
72 value: DbValue::Null,
73 });
74 self
75 }
76}