#[allow(unused_imports)]
use crate::{
client::Elasticsearch,
error::Error,
http::{
headers::{HeaderMap, HeaderName, HeaderValue},
request::{Body, JsonBody, NdBody},
response::Response,
Method,
},
params::*,
};
use serde::Serialize;
use serde_with;
use std::borrow::Cow;
#[derive(Debug, Clone, PartialEq)]
#[doc = "API parts for the Sql Clear Cursor API"]
pub enum SqlClearCursorParts {
#[doc = "No parts"]
None,
}
impl SqlClearCursorParts {
#[doc = "Builds a relative URL path to the Sql Clear Cursor API"]
pub fn url(self) -> Cow<'static, str> {
match self {
SqlClearCursorParts::None => "/_sql/close".into(),
}
}
}
#[derive(Clone, Debug)]
#[doc = "Builder for the Sql Clear Cursor API"]
pub struct SqlClearCursor<'a, 'b, B> {
client: &'a Elasticsearch,
parts: SqlClearCursorParts,
body: Option<B>,
error_trace: Option<bool>,
filter_path: Option<&'b [&'b str]>,
headers: HeaderMap,
human: Option<bool>,
pretty: Option<bool>,
source: Option<&'b str>,
}
impl<'a, 'b, B> SqlClearCursor<'a, 'b, B>
where
B: Body,
{
#[doc = "Creates a new instance of [SqlClearCursor]"]
pub fn new(client: &'a Elasticsearch) -> Self {
SqlClearCursor {
client,
parts: SqlClearCursorParts::None,
headers: HeaderMap::new(),
body: None,
error_trace: None,
filter_path: None,
human: None,
pretty: None,
source: None,
}
}
#[doc = "The body for the API call"]
pub fn body<T>(self, body: T) -> SqlClearCursor<'a, 'b, JsonBody<T>>
where
T: Serialize,
{
SqlClearCursor {
client: self.client,
parts: self.parts,
body: Some(body.into()),
error_trace: self.error_trace,
filter_path: self.filter_path,
headers: self.headers,
human: self.human,
pretty: self.pretty,
source: self.source,
}
}
#[doc = "Include the stack trace of returned errors."]
pub fn error_trace(mut self, error_trace: bool) -> Self {
self.error_trace = Some(error_trace);
self
}
#[doc = "A comma-separated list of filters used to reduce the response."]
pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
self.filter_path = Some(filter_path);
self
}
#[doc = "Adds a HTTP header"]
pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
self.headers.insert(key, value);
self
}
#[doc = "Return human readable values for statistics."]
pub fn human(mut self, human: bool) -> Self {
self.human = Some(human);
self
}
#[doc = "Pretty format the returned JSON response."]
pub fn pretty(mut self, pretty: bool) -> Self {
self.pretty = Some(pretty);
self
}
#[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
pub fn source(mut self, source: &'b str) -> Self {
self.source = Some(source);
self
}
#[doc = "Creates an asynchronous call to the Sql Clear Cursor API that can be awaited"]
pub async fn send(self) -> Result<Response, Error> {
let path = self.parts.url();
let method = Method::Post;
let headers = self.headers;
let query_string = {
#[serde_with::skip_serializing_none]
#[derive(Serialize)]
struct QueryParams<'b> {
#[serde(rename = "error_trace")]
error_trace: Option<bool>,
#[serde(
rename = "filter_path",
serialize_with = "crate::client::serialize_coll_qs"
)]
filter_path: Option<&'b [&'b str]>,
#[serde(rename = "human")]
human: Option<bool>,
#[serde(rename = "pretty")]
pretty: Option<bool>,
#[serde(rename = "source")]
source: Option<&'b str>,
}
let query_params = QueryParams {
error_trace: self.error_trace,
filter_path: self.filter_path,
human: self.human,
pretty: self.pretty,
source: self.source,
};
Some(query_params)
};
let body = self.body;
let response = self
.client
.send(method, &path, headers, query_string.as_ref(), body)
.await?;
Ok(response)
}
}
#[derive(Debug, Clone, PartialEq)]
#[doc = "API parts for the Sql Query API"]
pub enum SqlQueryParts {
#[doc = "No parts"]
None,
}
impl SqlQueryParts {
#[doc = "Builds a relative URL path to the Sql Query API"]
pub fn url(self) -> Cow<'static, str> {
match self {
SqlQueryParts::None => "/_sql".into(),
}
}
}
#[derive(Clone, Debug)]
#[doc = "Builder for the Sql Query API"]
pub struct SqlQuery<'a, 'b, B> {
client: &'a Elasticsearch,
parts: SqlQueryParts,
body: Option<B>,
error_trace: Option<bool>,
filter_path: Option<&'b [&'b str]>,
format: Option<&'b str>,
headers: HeaderMap,
human: Option<bool>,
pretty: Option<bool>,
source: Option<&'b str>,
}
impl<'a, 'b, B> SqlQuery<'a, 'b, B>
where
B: Body,
{
#[doc = "Creates a new instance of [SqlQuery]"]
pub fn new(client: &'a Elasticsearch) -> Self {
SqlQuery {
client,
parts: SqlQueryParts::None,
headers: HeaderMap::new(),
body: None,
error_trace: None,
filter_path: None,
format: None,
human: None,
pretty: None,
source: None,
}
}
#[doc = "The body for the API call"]
pub fn body<T>(self, body: T) -> SqlQuery<'a, 'b, JsonBody<T>>
where
T: Serialize,
{
SqlQuery {
client: self.client,
parts: self.parts,
body: Some(body.into()),
error_trace: self.error_trace,
filter_path: self.filter_path,
format: self.format,
headers: self.headers,
human: self.human,
pretty: self.pretty,
source: self.source,
}
}
#[doc = "Include the stack trace of returned errors."]
pub fn error_trace(mut self, error_trace: bool) -> Self {
self.error_trace = Some(error_trace);
self
}
#[doc = "A comma-separated list of filters used to reduce the response."]
pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
self.filter_path = Some(filter_path);
self
}
#[doc = "a short version of the Accept header, e.g. json, yaml"]
pub fn format(mut self, format: &'b str) -> Self {
self.format = Some(format);
self
}
#[doc = "Adds a HTTP header"]
pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
self.headers.insert(key, value);
self
}
#[doc = "Return human readable values for statistics."]
pub fn human(mut self, human: bool) -> Self {
self.human = Some(human);
self
}
#[doc = "Pretty format the returned JSON response."]
pub fn pretty(mut self, pretty: bool) -> Self {
self.pretty = Some(pretty);
self
}
#[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
pub fn source(mut self, source: &'b str) -> Self {
self.source = Some(source);
self
}
#[doc = "Creates an asynchronous call to the Sql Query API that can be awaited"]
pub async fn send(self) -> Result<Response, Error> {
let path = self.parts.url();
let method = match self.body {
Some(_) => Method::Post,
None => Method::Get,
};
let headers = self.headers;
let query_string = {
#[serde_with::skip_serializing_none]
#[derive(Serialize)]
struct QueryParams<'b> {
#[serde(rename = "error_trace")]
error_trace: Option<bool>,
#[serde(
rename = "filter_path",
serialize_with = "crate::client::serialize_coll_qs"
)]
filter_path: Option<&'b [&'b str]>,
#[serde(rename = "format")]
format: Option<&'b str>,
#[serde(rename = "human")]
human: Option<bool>,
#[serde(rename = "pretty")]
pretty: Option<bool>,
#[serde(rename = "source")]
source: Option<&'b str>,
}
let query_params = QueryParams {
error_trace: self.error_trace,
filter_path: self.filter_path,
format: self.format,
human: self.human,
pretty: self.pretty,
source: self.source,
};
Some(query_params)
};
let body = self.body;
let response = self
.client
.send(method, &path, headers, query_string.as_ref(), body)
.await?;
Ok(response)
}
}
#[derive(Debug, Clone, PartialEq)]
#[doc = "API parts for the Sql Translate API"]
pub enum SqlTranslateParts {
#[doc = "No parts"]
None,
}
impl SqlTranslateParts {
#[doc = "Builds a relative URL path to the Sql Translate API"]
pub fn url(self) -> Cow<'static, str> {
match self {
SqlTranslateParts::None => "/_sql/translate".into(),
}
}
}
#[derive(Clone, Debug)]
#[doc = "Builder for the Sql Translate API"]
pub struct SqlTranslate<'a, 'b, B> {
client: &'a Elasticsearch,
parts: SqlTranslateParts,
body: Option<B>,
error_trace: Option<bool>,
filter_path: Option<&'b [&'b str]>,
headers: HeaderMap,
human: Option<bool>,
pretty: Option<bool>,
source: Option<&'b str>,
}
impl<'a, 'b, B> SqlTranslate<'a, 'b, B>
where
B: Body,
{
#[doc = "Creates a new instance of [SqlTranslate]"]
pub fn new(client: &'a Elasticsearch) -> Self {
SqlTranslate {
client,
parts: SqlTranslateParts::None,
headers: HeaderMap::new(),
body: None,
error_trace: None,
filter_path: None,
human: None,
pretty: None,
source: None,
}
}
#[doc = "The body for the API call"]
pub fn body<T>(self, body: T) -> SqlTranslate<'a, 'b, JsonBody<T>>
where
T: Serialize,
{
SqlTranslate {
client: self.client,
parts: self.parts,
body: Some(body.into()),
error_trace: self.error_trace,
filter_path: self.filter_path,
headers: self.headers,
human: self.human,
pretty: self.pretty,
source: self.source,
}
}
#[doc = "Include the stack trace of returned errors."]
pub fn error_trace(mut self, error_trace: bool) -> Self {
self.error_trace = Some(error_trace);
self
}
#[doc = "A comma-separated list of filters used to reduce the response."]
pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
self.filter_path = Some(filter_path);
self
}
#[doc = "Adds a HTTP header"]
pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
self.headers.insert(key, value);
self
}
#[doc = "Return human readable values for statistics."]
pub fn human(mut self, human: bool) -> Self {
self.human = Some(human);
self
}
#[doc = "Pretty format the returned JSON response."]
pub fn pretty(mut self, pretty: bool) -> Self {
self.pretty = Some(pretty);
self
}
#[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
pub fn source(mut self, source: &'b str) -> Self {
self.source = Some(source);
self
}
#[doc = "Creates an asynchronous call to the Sql Translate API that can be awaited"]
pub async fn send(self) -> Result<Response, Error> {
let path = self.parts.url();
let method = match self.body {
Some(_) => Method::Post,
None => Method::Get,
};
let headers = self.headers;
let query_string = {
#[serde_with::skip_serializing_none]
#[derive(Serialize)]
struct QueryParams<'b> {
#[serde(rename = "error_trace")]
error_trace: Option<bool>,
#[serde(
rename = "filter_path",
serialize_with = "crate::client::serialize_coll_qs"
)]
filter_path: Option<&'b [&'b str]>,
#[serde(rename = "human")]
human: Option<bool>,
#[serde(rename = "pretty")]
pretty: Option<bool>,
#[serde(rename = "source")]
source: Option<&'b str>,
}
let query_params = QueryParams {
error_trace: self.error_trace,
filter_path: self.filter_path,
human: self.human,
pretty: self.pretty,
source: self.source,
};
Some(query_params)
};
let body = self.body;
let response = self
.client
.send(method, &path, headers, query_string.as_ref(), body)
.await?;
Ok(response)
}
}
#[doc = "Namespace client for Sql APIs"]
pub struct Sql<'a> {
client: &'a Elasticsearch,
}
impl<'a> Sql<'a> {
#[doc = "Creates a new instance of [Sql]"]
pub fn new(client: &'a Elasticsearch) -> Self {
Self { client }
}
pub fn clear_cursor<'b>(&'a self) -> SqlClearCursor<'a, 'b, ()> {
SqlClearCursor::new(&self.client)
}
pub fn query<'b>(&'a self) -> SqlQuery<'a, 'b, ()> {
SqlQuery::new(&self.client)
}
pub fn translate<'b>(&'a self) -> SqlTranslate<'a, 'b, ()> {
SqlTranslate::new(&self.client)
}
}
impl Elasticsearch {
#[doc = "Creates a namespace client for Sql APIs"]
pub fn sql(&self) -> Sql {
Sql::new(&self)
}
}