nebula_client/v1/meta/
client.rs

1use bytes::Bytes;
2use fbthrift::{BinaryProtocol, Transport};
3use nebula_fbthrift_meta_v1::{
4    client::{MetaService, MetaServiceImpl},
5    errors::meta_service::{GetSpaceError, ListPartsError, ListSpacesError, ListTagsError},
6    types::{
7        GetSpaceReq, GetSpaceResp, ListEdgesReq, ListEdgesResp, ListPartsReq, ListPartsResp,
8        ListSpacesReq, ListSpacesResp, ListTagsReq, ListTagsResp,
9    },
10};
11
12//
13//
14//
15struct MetaConnection<T>
16where
17    T: Transport,
18    Bytes: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
19    ::fbthrift::ProtocolEncoded<BinaryProtocol>:
20        ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
21{
22    service: MetaServiceImpl<BinaryProtocol, T>,
23}
24
25impl<T> MetaConnection<T>
26where
27    T: Transport,
28    Bytes: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
29    ::fbthrift::ProtocolEncoded<BinaryProtocol>:
30        ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
31{
32    fn new(transport: T) -> Self {
33        Self {
34            service: MetaServiceImpl::<BinaryProtocol, _>::new(transport),
35        }
36    }
37}
38
39//
40//
41//
42pub struct MetaClient<T>
43where
44    T: Transport,
45    Bytes: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
46    ::fbthrift::ProtocolEncoded<BinaryProtocol>:
47        ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
48{
49    connection: MetaConnection<T>,
50}
51
52impl<T> MetaClient<T>
53where
54    T: Transport,
55    Bytes: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
56    ::fbthrift::ProtocolEncoded<BinaryProtocol>:
57        ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
58{
59    pub fn new(transport: T) -> Self {
60        Self {
61            connection: MetaConnection::new(transport),
62        }
63    }
64
65    pub async fn list_spaces(&self) -> Result<ListSpacesResp, ListSpacesError> {
66        self.connection
67            .service
68            .listSpaces(&ListSpacesReq {
69                ..Default::default()
70            })
71            .await
72    }
73
74    pub async fn get_space(&self, space_name: &str) -> Result<GetSpaceResp, GetSpaceError> {
75        self.connection
76            .service
77            .getSpace(&GetSpaceReq {
78                space_name: space_name.to_owned(),
79                ..Default::default()
80            })
81            .await
82    }
83
84    // part_id from 1
85    pub async fn list_parts(
86        &self,
87        space_id: i32,
88        part_ids: Vec<i32>,
89    ) -> Result<ListPartsResp, ListPartsError> {
90        self.connection
91            .service
92            .listParts(&ListPartsReq {
93                space_id,
94                part_ids,
95                ..Default::default()
96            })
97            .await
98    }
99
100    pub async fn list_tags(&self, space_id: i32) -> Result<ListTagsResp, ListTagsError> {
101        self.connection
102            .service
103            .listTags(&ListTagsReq {
104                space_id,
105                ..Default::default()
106            })
107            .await
108    }
109
110    pub async fn list_edges(&self, space_id: i32) -> Result<ListEdgesResp, ListTagsError> {
111        self.connection
112            .service
113            .listEdges(&ListEdgesReq {
114                space_id,
115                ..Default::default()
116            })
117            .await
118    }
119}