nullnet_libdatastore/
experimental.rs

1use crate::{
2    DatastoreConfig,
3    store::{self, store_service_client::StoreServiceClient},
4};
5use nullnet_liberror::{Error, ErrorHandler, Location, location};
6use tonic::transport::Channel;
7
8#[derive(Debug, Clone)]
9pub struct ExperimentalDatastoreClient {
10    client: StoreServiceClient<Channel>,
11}
12
13impl ExperimentalDatastoreClient {
14    #[allow(clippy::missing_errors_doc)]
15    pub async fn new(config: DatastoreConfig) -> Result<Self, Error> {
16        let channel = config.connect().await?;
17        let client = StoreServiceClient::new(channel).max_decoding_message_size(50 * 1024 * 1024);
18        Ok(Self { client })
19    }
20
21    pub async fn create_connections(
22        &mut self,
23        request: store::CreateConnectionsRequest,
24    ) -> Result<store::CreateConnectionsResponse, Error> {
25        let response = self
26            .client
27            .create_connections(request)
28            .await
29            .handle_err(location!())?;
30
31        Ok(response.into_inner())
32    }
33
34    pub async fn get_connections(
35        &mut self,
36        request: store::GetConnectionsRequest,
37    ) -> Result<store::GetConnectionsResponse, Error> {
38        let response = self
39            .client
40            .get_connections(request)
41            .await
42            .handle_err(location!())?;
43
44        Ok(response.into_inner())
45    }
46
47    pub async fn update_connections(
48        &mut self,
49        request: store::UpdateConnectionsRequest,
50    ) -> Result<store::UpdateConnectionsResponse, Error> {
51        let response = self
52            .client
53            .update_connections(request)
54            .await
55            .handle_err(location!())?;
56
57        Ok(response.into_inner())
58    }
59
60    pub async fn delete_connections(
61        &mut self,
62        request: store::DeleteConnectionsRequest,
63    ) -> Result<store::DeleteConnectionsResponse, Error> {
64        let response = self
65            .client
66            .delete_connections(request)
67            .await
68            .handle_err(location!())?;
69
70        Ok(response.into_inner())
71    }
72}