Skip to main content

solidb_client/client/
query.rs

1use super::SoliDBClient;
2use crate::protocol::{Command, DriverError};
3use serde_json::Value;
4use std::collections::HashMap;
5
6impl SoliDBClient {
7    pub async fn query(
8        &mut self,
9        database: &str,
10        sdbql: &str,
11        bind_vars: Option<HashMap<String, Value>>,
12    ) -> Result<Vec<Value>, DriverError> {
13        let response = self
14            .send_command(Command::Query {
15                database: database.to_string(),
16                sdbql: sdbql.to_string(),
17                bind_vars,
18            })
19            .await?;
20
21        let data = Self::extract_data(response)?
22            .ok_or_else(|| DriverError::ProtocolError("Expected data".to_string()))?;
23
24        serde_json::from_value(data)
25            .map_err(|e| DriverError::ProtocolError(format!("Invalid response: {}", e)))
26    }
27
28    pub async fn explain(
29        &mut self,
30        database: &str,
31        sdbql: &str,
32        bind_vars: Option<HashMap<String, Value>>,
33    ) -> Result<Value, DriverError> {
34        let response = self
35            .send_command(Command::Explain {
36                database: database.to_string(),
37                sdbql: sdbql.to_string(),
38                bind_vars,
39            })
40            .await?;
41        Self::extract_data(response)?
42            .ok_or_else(|| DriverError::ProtocolError("Expected data".to_string()))
43    }
44}