manticore_openapi/apis/
utils_api.rs

1/*
2 * Manticore Search Client
3 *
4 * Сlient for Manticore Search.
5 *
6 * The version of the OpenAPI document: 3.3.1
7 * Contact: info@manticoresearch.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`sql`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum SqlError {
20    DefaultResponse(models::ErrorResponse),
21    UnknownValue(serde_json::Value),
22}
23
24/// Run a query in SQL format. Expects a query string passed through `body` parameter and optional `raw_response` parameter that defines a format of response. `raw_response` can be set to `False` for Select queries only, e.g., `SELECT * FROM myindex` The query string must stay as it is, no URL encoding is needed. The response object depends on the query executed. In select mode the response has same format as `/search` operation.
25pub async fn sql(
26    configuration: &configuration::Configuration,
27    body: &str,
28    raw_response: Option<bool>,
29) -> Result<Vec<serde_json::Value>, Error<SqlError>> {
30    let local_var_configuration = configuration;
31
32    let local_var_client = &local_var_configuration.client;
33
34    let local_var_uri_str = format!("{}/sql", local_var_configuration.base_path);
35    let mut local_var_req_builder =
36        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
37
38    if let Some(ref local_var_str) = raw_response {
39        local_var_req_builder =
40            local_var_req_builder.query(&[("raw_response", &local_var_str.to_string())]);
41    }
42    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
43        local_var_req_builder =
44            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
45    }
46    local_var_req_builder = local_var_req_builder.json(&body);
47
48    let local_var_req = local_var_req_builder.build()?;
49    let local_var_resp = local_var_client.execute(local_var_req).await?;
50
51    let local_var_status = local_var_resp.status();
52    let local_var_content = local_var_resp.text().await?;
53
54    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
55        serde_json::from_str(&local_var_content).map_err(Error::from)
56    } else {
57        let local_var_entity: Option<SqlError> = serde_json::from_str(&local_var_content).ok();
58        let local_var_error = ResponseContent {
59            status: local_var_status,
60            content: local_var_content,
61            entity: local_var_entity,
62        };
63        Err(Error::ResponseError(local_var_error))
64    }
65}
66
67/// Run a query in SQL format. Expects a query string passed through `body` parameter and optional `raw_response` parameter that defines a format of response. `raw_response` can be set to `False` for Select queries only, e.g., `SELECT * FROM myindex` The query string must stay as it is, no URL encoding is needed. The response object depends on the query executed. In select mode the response has same format as `/search` operation.
68pub async fn cli(
69    configuration: &configuration::Configuration,
70    body: &str,
71) -> Result<String, Error<SqlError>> {
72    let local_var_configuration = configuration;
73
74    let local_var_client = &local_var_configuration.client;
75
76    let local_var_uri_str = format!("{}/cli", local_var_configuration.base_path);
77    let mut local_var_req_builder =
78        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81        local_var_req_builder =
82            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84    local_var_req_builder = local_var_req_builder.body(body.to_string());
85    let local_var_req = local_var_req_builder.build()?;
86    let local_var_resp = local_var_client.execute(local_var_req).await?;
87    let local_var_status = local_var_resp.status();
88    let local_var_content = local_var_resp.text().await?;
89    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
90        Ok(local_var_content)
91    } else {
92        let local_var_entity: Option<SqlError> = serde_json::from_str(&local_var_content).ok();
93        let local_var_error = ResponseContent {
94            status: local_var_status,
95            content: local_var_content,
96            entity: local_var_entity,
97        };
98        Err(Error::ResponseError(local_var_error))
99    }
100}