1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::error::ProtonClientError;
use crate::{alias, ProtonClient};

impl ProtonClient {
    /// Executes a query against Proton.
    ///
    /// Pass a query string to run against the Proton data. Returns the result.
    ///
    /// # Arguments
    ///
    /// * `query` - The query string to execute
    ///
    /// # Errors
    ///
    /// This method will return an error if:
    ///
    /// - The API call fails
    /// - Query syntax is invalid
    ///
    /// # Example
    ///
    /// ```no_run
    ///  use proton_client::ProtonClient;
    ///  use proton_client::prelude::Result;
    ///
    ///  async fn example() -> Result<()> {
    ///
    ///  let client = ProtonClient::new("http://localhost:8123");
    ///
    ///      client
    ///         .execute_query("CREATE STREAM IF NOT EXISTS test_stream(no uint32, name string) ORDER BY no")
    ///         .await
    ///         .expect("Failed to execute query");
    ///
    ///   Ok(())
    /// }
    pub async fn execute_query(&self, query: &str) -> alias::Result<()> {
        match self.client.query(query).execute().await {
            Ok(_) => Ok(()),
            Err(e) => Err(ProtonClientError::QueryFailed(e.to_string())),
        }
    }
}