nullnet_libdatastore/builders/
get_by_id_request_builder.rs1use crate::{GetByIdRequest, Params, Query};
2
3#[derive(Debug, Default)]
4pub struct GetByIdRequestBuilder {
5 id: Option<String>,
6 table: Option<String>,
7 pluck: Option<String>,
8 durability: Option<String>,
9 is_root: bool,
10}
11
12impl GetByIdRequestBuilder {
13 pub fn new() -> Self {
14 Self::default()
15 }
16
17 pub fn id(mut self, id: impl Into<String>) -> Self {
18 self.id = Some(id.into());
19 self
20 }
21
22 pub fn table(mut self, table: impl Into<String>) -> Self {
23 self.table = Some(table.into());
24 self
25 }
26
27 pub fn pluck<I, S>(mut self, fields: I) -> Self
28 where
29 I: IntoIterator<Item = S>,
30 S: Into<String>,
31 {
32 let joined = fields
33 .into_iter()
34 .map(Into::into)
35 .collect::<Vec<_>>()
36 .join(",");
37
38 self.pluck = Some(joined);
39 self
40 }
41
42 pub fn durability(mut self, durability: impl Into<String>) -> Self {
43 self.durability = Some(durability.into());
44 self
45 }
46
47 pub fn performed_by_root(mut self, value: bool) -> Self {
48 self.is_root = value;
49 self
50 }
51
52 pub fn build(self) -> GetByIdRequest {
53 GetByIdRequest {
54 params: Some(Params {
55 id: self.id.unwrap_or_default(),
56 table: self.table.unwrap_or_default(),
57 r#type: if self.is_root {
58 String::from("root")
59 } else {
60 String::new()
61 },
62 }),
63 query: Some(Query {
64 pluck: self.pluck.unwrap_or_default(),
65 durability: self.durability.unwrap_or_default(),
66 }),
67 }
68 }
69}