/*
* Hotdata API
*
* Powerful data platform API for managed databases, queries, and analytics.
*
* The version of the OpenAPI document: 1.0.0
* Contact: developers@hotdata.dev
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`information_schema`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InformationSchemaError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// List discovered tables with optional filtering and pagination. Supports wildcard patterns (SQL %) for schema and table name filters. Set include_columns=true to include column definitions (omitted by default). Every table carries its declared storage layout — `partition_by` and `sorted_by` — which is fixed when the table is created and cannot be changed afterwards. Both are always present; an empty array means none was declared. Only tables in a hotdata-managed database declare a layout here, so a table discovered from an external connection always reports empty arrays.
pub async fn information_schema(
configuration: &configuration::Configuration,
connection_id: Option<&str>,
schema: Option<&str>,
table: Option<&str>,
include_columns: Option<bool>,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::InformationSchemaResponse, Error<InformationSchemaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_connection_id = connection_id;
let p_query_schema = schema;
let p_query_table = table;
let p_query_include_columns = include_columns;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!("{}/v1/information_schema", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_connection_id {
req_builder = req_builder.query(&[("connection_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_schema {
req_builder = req_builder.query(&[("schema", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_table {
req_builder = req_builder.query(&[("table", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_include_columns {
req_builder = req_builder.query(&[("include_columns", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
// Route through the shared retry helper so HTTP 429 (OVERLOADED admission
// shedding) is retried per `configuration.retry` on every generated op, not
// just the hand-written query path. See crate::http::execute_retrying.
let resp =
crate::http::execute_retrying(&configuration.client, req, &configuration.retry).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InformationSchemaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InformationSchemaResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<InformationSchemaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}