solidb_client/client/
index.rs1use super::SoliDBClient;
2use crate::protocol::{Command, DriverError};
3use serde_json::Value;
4
5impl SoliDBClient {
6 pub async fn create_index(
7 &mut self,
8 database: &str,
9 collection: &str,
10 name: &str,
11 fields: Vec<String>,
12 unique: bool,
13 sparse: bool,
14 ) -> Result<(), DriverError> {
15 let response = self
16 .send_command(Command::CreateIndex {
17 database: database.to_string(),
18 collection: collection.to_string(),
19 name: name.to_string(),
20 fields,
21 unique,
22 sparse,
23 })
24 .await?;
25 Self::extract_data(response)?;
26 Ok(())
27 }
28
29 pub async fn delete_index(
30 &mut self,
31 database: &str,
32 collection: &str,
33 name: &str,
34 ) -> Result<(), DriverError> {
35 let response = self
36 .send_command(Command::DeleteIndex {
37 database: database.to_string(),
38 collection: collection.to_string(),
39 name: name.to_string(),
40 })
41 .await?;
42 Self::extract_data(response)?;
43 Ok(())
44 }
45
46 pub async fn list_indexes(
47 &mut self,
48 database: &str,
49 collection: &str,
50 ) -> Result<Vec<Value>, DriverError> {
51 let response = self
52 .send_command(Command::ListIndexes {
53 database: database.to_string(),
54 collection: collection.to_string(),
55 })
56 .await?;
57 let data = Self::extract_data(response)?
58 .ok_or_else(|| DriverError::ProtocolError("Expected data".to_string()))?;
59
60 serde_json::from_value(data)
61 .map_err(|e| DriverError::ProtocolError(format!("Invalid response: {}", e)))
62 }
63}