nullnet_libdatastore/builders/
create_request_builder.rs

1use crate::datastore::{CreateBody, CreateParams, CreateRequest, Query};
2
3#[derive(Debug, Default)]
4pub struct CreateRequestBuilder {
5    table: Option<String>,
6    durability: Option<String>,
7    pluck: Option<String>,
8    record: Option<String>,
9}
10
11impl CreateRequestBuilder {
12    pub fn new() -> Self {
13        Self::default()
14    }
15
16    pub fn table(mut self, table: impl Into<String>) -> Self {
17        self.table = Some(table.into());
18        self
19    }
20
21    pub fn durability(mut self, durability: impl Into<String>) -> Self {
22        self.durability = Some(durability.into());
23        self
24    }
25
26    pub fn pluck<I, S>(mut self, fields: I) -> Self
27    where
28        I: IntoIterator<Item = S>,
29        S: Into<String>,
30    {
31        let joined = fields
32            .into_iter()
33            .map(Into::into)
34            .collect::<Vec<_>>()
35            .join(",");
36        self.pluck = Some(joined);
37        self
38    }
39
40    pub fn record(mut self, value: impl Into<String>) -> Self {
41        self.record = Some(value.into());
42        self
43    }
44
45    pub fn build(self) -> CreateRequest {
46        CreateRequest {
47            params: Some(CreateParams {
48                table: self.table.unwrap_or_default(),
49            }),
50            query: Some(Query {
51                pluck: self.pluck.unwrap_or_default(),
52                durability: self.durability.unwrap_or_default(),
53            }),
54            body: Some(CreateBody {
55                record: self.record.unwrap_or_default(),
56            }),
57        }
58    }
59}