nullnet_libdatastore/builders/
join_builder.rs1use crate::datastore::{AdvanceFilter, EntityFieldFrom, EntityFieldTo, FieldRelation, Join};
2
3#[derive(Debug, Default)]
4pub struct JoinBuilder {
5 r#type: String,
6 to_entity: String,
7 to_field: String,
8 to_alias: String,
9 to_limit: i32,
10 to_order_by: String,
11 to_filters: Vec<AdvanceFilter>,
12 from_entity: String,
13 from_field: String,
14}
15
16impl JoinBuilder {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn r#type(mut self, value: impl Into<String>) -> Self {
22 self.r#type = value.into();
23 self
24 }
25
26 #[allow(clippy::wrong_self_convention)]
27 pub fn to_entity(mut self, value: impl Into<String>) -> Self {
28 self.to_entity = value.into();
29 self
30 }
31
32 #[allow(clippy::wrong_self_convention)]
33 pub fn to_field(mut self, value: impl Into<String>) -> Self {
34 self.to_field = value.into();
35 self
36 }
37
38 #[allow(clippy::wrong_self_convention)]
39 pub fn to_alias(mut self, value: impl Into<String>) -> Self {
40 self.to_alias = value.into();
41 self
42 }
43
44 #[allow(clippy::wrong_self_convention)]
45 pub fn to_limit(mut self, value: i32) -> Self {
46 self.to_limit = value;
47 self
48 }
49
50 #[allow(clippy::wrong_self_convention)]
51 pub fn to_order_by(mut self, value: impl Into<String>) -> Self {
52 self.to_order_by = value.into();
53 self
54 }
55
56 #[allow(clippy::wrong_self_convention)]
57 pub fn to_filter(mut self, filter: AdvanceFilter) -> Self {
58 self.to_filters.push(filter);
59 self
60 }
61
62 #[allow(clippy::wrong_self_convention)]
63 pub fn to_filters(mut self, filters: impl IntoIterator<Item = AdvanceFilter>) -> Self {
64 self.to_filters.extend(filters);
65 self
66 }
67
68 #[allow(clippy::wrong_self_convention)]
69 pub fn from_entity(mut self, value: impl Into<String>) -> Self {
70 self.from_entity = value.into();
71 self
72 }
73
74 #[allow(clippy::wrong_self_convention)]
75 pub fn from_field(mut self, value: impl Into<String>) -> Self {
76 self.from_field = value.into();
77 self
78 }
79
80 pub fn build(self) -> Join {
81 Join {
82 r#type: self.r#type,
83 field_relation: Some(FieldRelation {
84 to: Some(EntityFieldTo {
85 entity: self.to_entity,
86 field: self.to_field,
87 alias: self.to_alias,
88 limit: self.to_limit,
89 order_by: self.to_order_by,
90 filters: self.to_filters,
91 }),
92 from: Some(EntityFieldFrom {
93 entity: self.from_entity,
94 field: self.from_field,
95 }),
96 }),
97 }
98 }
99}