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.

/// Get async SQL search results.
///
/// Get the current status and available results for an async SQL search or stored synchronous SQL search.
///
/// If the Elasticsearch security features are enabled, only the user who first submitted the SQL search can retrieve the search using this API.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct Request {
    // Path parameters.
    /// The identifier for the search.
    pub id: ::oxsearch_core::Id,
    // Query parameters.
    /// The separator for CSV results.
    /// The API supports this parameter only for CSV responses.
    pub delimiter: ::core::option::Option<::std::string::String>,
    /// The format for the response.
    /// You must specify a format using this parameter or the `Accept` HTTP header.
    /// If you specify both, the API uses this parameter.
    pub format: ::core::option::Option<::std::string::String>,
    /// The retention period for the search and its results.
    /// It defaults to the `keep_alive` period for the original SQL search.
    pub keep_alive: ::core::option::Option<::oxsearch_core::Duration>,
    /// The period to wait for complete results.
    /// It defaults to no timeout, meaning the request waits for complete search results.
    pub wait_for_completion_timeout: ::core::option::Option<::oxsearch_core::Duration>,
}

impl Request {
    /// A `Request` with its required properties set.
    pub fn new(id: impl ::core::convert::Into<::oxsearch_core::Id>) -> Self {
        Self {
            id: id.into(),
            delimiter: ::core::option::Option::None,
            format: ::core::option::Option::None,
            keep_alive: ::core::option::Option::None,
            wait_for_completion_timeout: ::core::option::Option::None,
        }
    }
}

impl Request {
    /// Sets `delimiter`.
    pub fn delimiter(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.delimiter = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `format`.
    pub fn format(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.format = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `keep_alive`.
    pub fn keep_alive(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
    ) -> Self {
        self.keep_alive = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `wait_for_completion_timeout`.
    pub fn wait_for_completion_timeout(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
    ) -> Self {
        self.wait_for_completion_timeout = ::core::option::Option::Some(value.into());
        self
    }
}

#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
#[non_exhaustive]
pub struct Response {
    /// Identifier for the search.
    /// This value is returned only for async and saved synchronous searches.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-ID` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub id: ::core::option::Option<::oxsearch_core::Id>,
    /// If `true`, the search is still running.
    /// If `false`, the search has finished.
    /// This value is returned only for async and saved synchronous searches.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-partial` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub is_running: ::core::option::Option<bool>,
    /// If `true`, the response does not contain complete search results.
    /// If `is_partial` is `true` and `is_running` is `true`, the search is still running.
    /// If `is_partial` is `true` but `is_running` is `false`, the results are partial due to a failure or timeout.
    /// This value is returned only for async and saved synchronous searches.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-partial` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub is_partial: ::core::option::Option<bool>,
    /// Column headings for the search results. Each object is a column.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub columns: ::core::option::Option<::std::vec::Vec<crate::Column>>,
    /// The cursor for the next set of paginated results.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Cursor` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub cursor: ::core::option::Option<::std::string::String>,
    /// The values for the search results.
    #[serde(default = "::core::default::Default::default")]
    pub rows: ::std::vec::Vec<crate::Row>,
}

impl Response {
    /// A `Response` with its required properties set.
    pub fn new(
        id: impl ::core::convert::Into<::oxsearch_core::Id>,
        is_running: bool,
        is_partial: bool,
        rows: impl ::core::convert::Into<::std::vec::Vec<crate::Row>>,
    ) -> Self {
        Self {
            id: ::core::option::Option::Some(id.into()),
            is_running: ::core::option::Option::Some(is_running.into()),
            is_partial: ::core::option::Option::Some(is_partial.into()),
            columns: ::core::option::Option::None,
            cursor: ::core::option::Option::None,
            rows: rows.into(),
        }
    }
}

impl Response {
    /// Sets `columns`.
    pub fn columns(
        mut self,
        value: impl ::core::convert::Into<::std::vec::Vec<crate::Column>>,
    ) -> Self {
        self.columns = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `cursor`.
    pub fn cursor(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.cursor = ::core::option::Option::Some(value.into());
        self
    }
}

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

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

    fn route(&self) -> ::core::result::Result<::oxsearch_core::Route, ::oxsearch_core::Error> {
        if let (::core::option::Option::Some(p0),) = (::core::option::Option::Some(&self.id),) {
            return ::core::result::Result::Ok(::oxsearch_core::Route::new(
                ::oxsearch_core::Method::Get,
                format!(
                    "/_sql/async/{}",
                    ::oxsearch_core::__private::path_param("id", p0)?
                ),
            ));
        }
        ::core::result::Result::Err(::oxsearch_core::__private::no_route(self.name()))
    }

    fn query(
        &self,
    ) -> ::core::result::Result<
        ::std::vec::Vec<(&'static str, ::std::string::String)>,
        ::oxsearch_core::Error,
    > {
        let mut query = ::std::vec::Vec::new();
        if let ::core::option::Option::Some(value) = &self.delimiter {
            query.push((
                "delimiter",
                ::oxsearch_core::__private::query_param("delimiter", value)?,
            ));
        }
        if let ::core::option::Option::Some(value) = &self.format {
            query.push((
                "format",
                ::oxsearch_core::__private::query_param("format", value)?,
            ));
        }
        if let ::core::option::Option::Some(value) = &self.keep_alive {
            query.push((
                "keep_alive",
                ::oxsearch_core::__private::query_param("keep_alive", value)?,
            ));
        }
        if let ::core::option::Option::Some(value) = &self.wait_for_completion_timeout {
            query.push((
                "wait_for_completion_timeout",
                ::oxsearch_core::__private::query_param("wait_for_completion_timeout", value)?,
            ));
        }
        ::core::result::Result::Ok(query)
    }

    fn body(
        &self,
    ) -> ::core::result::Result<::core::option::Option<::oxsearch_core::Body>, ::oxsearch_core::Error>
    {
        ::core::result::Result::Ok(::core::option::Option::None)
    }
}