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