oxsearch-sql 0.2.0

SQL for oxsearch, generated from the Elasticsearch specification: queries, cursors and their translation into search requests
Documentation
// Generated by `cargo run -p xtask -- generate` from elastic/elasticsearch-specification 9.5 at
// 84bf510a907bae62ffe29af35f516af287a79eab. Don't edit it: change the generator.

/// The request's body.
#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
#[non_exhaustive]
pub struct RequestBody {
    /// The maximum number of rows (or entries) to return in one response.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub fetch_size: ::core::option::Option<i32>,
    /// The Elasticsearch query DSL for additional filtering.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub filter: ::core::option::Option<::oxsearch_core::query_dsl::QueryContainer>,
    /// The SQL query to run.
    pub query: ::std::string::String,
    /// The ISO-8601 time zone ID for the search.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub time_zone: ::core::option::Option<::oxsearch_core::TimeZone>,
}

impl RequestBody {
    /// A `RequestBody` with its required properties set.
    pub fn new(query: impl ::core::convert::Into<::std::string::String>) -> Self {
        Self {
            fetch_size: ::core::option::Option::None,
            filter: ::core::option::Option::None,
            query: query.into(),
            time_zone: ::core::option::Option::None,
        }
    }
}

impl RequestBody {
    /// Sets `fetch_size`.
    pub fn fetch_size(mut self, value: i32) -> Self {
        self.fetch_size = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `filter`.
    pub fn filter(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::query_dsl::QueryContainer>,
    ) -> Self {
        self.filter = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `time_zone`.
    pub fn time_zone(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::TimeZone>,
    ) -> Self {
        self.time_zone = ::core::option::Option::Some(value.into());
        self
    }
}

/// Translate SQL into Elasticsearch queries.
///
/// Translate an SQL search into a search API request containing Query DSL.
/// It accepts the same request body parameters as the SQL search API, excluding `cursor`.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct Request {
    /// The body.
    pub body: ::core::option::Option<crate::translate::RequestBody>,
}

impl Request {
    /// A `Request` with its required properties set.
    pub fn new() -> Self {
        Self {
            body: ::core::option::Option::None,
        }
    }
}

impl Request {
    /// Sets `body`.
    pub fn body(
        mut self,
        value: impl ::core::convert::Into<crate::translate::RequestBody>,
    ) -> Self {
        self.body = ::core::option::Option::Some(value.into());
        self
    }
}

#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
#[non_exhaustive]
pub struct Response {
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub aggregations: ::core::option::Option<
        ::indexmap::IndexMap<::std::string::String, ::oxsearch_aggs::AggregationContainer>,
    >,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub size: ::core::option::Option<i64>,
    #[serde(
        rename = "_source",
        skip_serializing_if = "::core::option::Option::is_none"
    )]
    pub source: ::core::option::Option<::oxsearch_core::search::SourceConfig>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub fields: ::core::option::Option<::std::vec::Vec<::oxsearch_core::query_dsl::FieldAndFormat>>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub query: ::core::option::Option<::oxsearch_core::query_dsl::QueryContainer>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub sort: ::core::option::Option<::oxsearch_core::Sort>,
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub track_total_hits: ::core::option::Option<::oxsearch_search::search::TrackHits>,
}

impl Response {
    /// A `Response` with its required properties set.
    pub fn new() -> Self {
        Self {
            aggregations: ::core::option::Option::None,
            size: ::core::option::Option::None,
            source: ::core::option::Option::None,
            fields: ::core::option::Option::None,
            query: ::core::option::Option::None,
            sort: ::core::option::Option::None,
            track_total_hits: ::core::option::Option::None,
        }
    }
}

impl Response {
    /// Sets `aggregations`.
    pub fn aggregations(
        mut self,
        value: impl ::core::convert::Into<
            ::indexmap::IndexMap<::std::string::String, ::oxsearch_aggs::AggregationContainer>,
        >,
    ) -> Self {
        self.aggregations = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `size`.
    pub fn size(mut self, value: i64) -> Self {
        self.size = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `source`.
    pub fn source(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::search::SourceConfig>,
    ) -> Self {
        self.source = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `fields`.
    pub fn fields(
        mut self,
        value: impl ::core::convert::Into<::std::vec::Vec<::oxsearch_core::query_dsl::FieldAndFormat>>,
    ) -> Self {
        self.fields = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `query`.
    pub fn query(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::query_dsl::QueryContainer>,
    ) -> Self {
        self.query = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `sort`.
    pub fn sort(mut self, value: impl ::core::convert::Into<::oxsearch_core::Sort>) -> Self {
        self.sort = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `track_total_hits`.
    pub fn track_total_hits(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_search::search::TrackHits>,
    ) -> Self {
        self.track_total_hits = ::core::option::Option::Some(value.into());
        self
    }
}

impl ::oxsearch_core::Endpoint for Request {
    type Response = crate::translate::Response;

    fn name(&self) -> &'static str {
        "sql.translate"
    }

    fn route(&self) -> ::core::result::Result<::oxsearch_core::Route, ::oxsearch_core::Error> {
        ::core::result::Result::Ok(::oxsearch_core::Route::new(
            if self.body.is_some() {
                ::oxsearch_core::Method::Post
            } else {
                ::oxsearch_core::Method::Get
            },
            "/_sql/translate",
        ))
    }

    fn query(
        &self,
    ) -> ::core::result::Result<
        ::std::vec::Vec<(&'static str, ::std::string::String)>,
        ::oxsearch_core::Error,
    > {
        ::core::result::Result::Ok(::std::vec::Vec::new())
    }

    fn body(
        &self,
    ) -> ::core::result::Result<::core::option::Option<::oxsearch_core::Body>, ::oxsearch_core::Error>
    {
        self.body
            .as_ref()
            .map(|body| ::oxsearch_core::__private::json_body(body))
            .transpose()
    }
}