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