meilisearch_api_client/
client.rs1use crate::{
2 indexes,
3 documents,
4};
5use crate::Config;
6use crate::error::ServiceError;
7use crate::{
8 Index,
9 Indexes,
10
11 CreateIndexRequest,
12 UpdateIndexRequest,
13 DeleteIndexRequest,
14};
15use crate::{
16 Document,
17 DocumentRequest,
18 DocumentState,
19};
20
21pub struct Client {
22 pub config: Config,
23}
24
25impl Client {
27 pub fn new(config: Config) -> Self {
28 Client {
29 config
30 }
31 }
32}
33
34impl Client {
36 pub async fn get_indexes(&self) -> Result<Indexes, ServiceError> {
37 indexes::get_indexes(&self.config).await
38 }
39
40 pub async fn get_index(&self, uid: &'static str) -> Result<Index, ServiceError> {
41 indexes::get_index(&self.config, uid).await
42 }
43
44 pub async fn create_index(&self, create_index_req: CreateIndexRequest) -> Result<Index, ServiceError> {
45 indexes::create_index(&self.config, create_index_req).await
46 }
47
48 pub async fn update_index(&self, update_index_req: UpdateIndexRequest) -> Result<Index, ServiceError> {
49 indexes::update_index(&self.config, update_index_req).await
50 }
51
52 pub async fn delete_index(&self, delete_index_req: DeleteIndexRequest) -> Result<String, ServiceError> {
53 indexes::delete_index(&self.config, delete_index_req).await
54 }
55}
56
57impl Client {
59 pub async fn get_document<T: Document>(&self, uid: String, did: String) -> Result<T, ServiceError> {
60 documents::get_document(&self.config, uid, did).await
61 }
62
63 pub async fn get_documents<T: Document>(&self, uid: String, offset: Option<usize>, limit: Option<usize>, attributes: Option<&str>) -> Result<Vec<T>, ServiceError> {
64 documents::get_documents::<T>(&self.config, uid, offset, limit, attributes).await
65 }
66
67 pub async fn add_or_replace<T: Document>(&self, document_req: DocumentRequest<T>) -> Result<DocumentState, ServiceError> {
68 documents::add_or_replace(&self.config, document_req).await
69 }
70}