/*
* Hotdata API
*
* Powerful data platform API for instant 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 [`add_database_schema`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddDatabaseSchemaError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`add_database_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddDatabaseTableError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`attach_database_catalog`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AttachDatabaseCatalogError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`bulk_create_databases`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkCreateDatabasesError {
Status400(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`count_databases`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CountDatabasesError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_database`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateDatabaseError {
Status400(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
Status500(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_database`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteDatabaseError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_database_batch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteDatabaseBatchError {
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`detach_database_catalog`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DetachDatabaseCatalogError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`fork_database`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ForkDatabaseError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_database`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDatabaseError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_database_batch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDatabaseBatchError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_database_lineage`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDatabaseLineageError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_databases`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListDatabasesError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`load_database_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LoadDatabaseTableError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
Status413(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`lookup_database_by_name`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LookupDatabaseByNameError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// Declare a new schema (and optionally its tables) on the database's auto-created default catalog after creation. The schema becomes reachable inside the database scope (e.g. `default.<schema>.<table>` and `information_schema.schemata`) without the caller naming the database's default connection. Identifiers are normalized to lowercase.
pub async fn add_database_schema(
configuration: &configuration::Configuration,
database_id: &str,
add_managed_schema_request: models::AddManagedSchemaRequest,
) -> Result<models::ManagedSchemaResponse, Error<AddDatabaseSchemaError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_body_add_managed_schema_request = add_managed_schema_request;
let uri_str = format!(
"{}/v1/databases/{database_id}/schemas",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_add_managed_schema_request);
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, req).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::ManagedSchemaResponse`"))),
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::ManagedSchemaResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<AddDatabaseSchemaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Declare a new table on an existing schema of the database's default catalog after creation. The table is added empty (declared-but-unloaded) and can be populated via the managed-table load endpoint targeting the default connection. Identifiers are normalized to lowercase.
pub async fn add_database_table(
configuration: &configuration::Configuration,
database_id: &str,
schema: &str,
add_managed_table_request: models::AddManagedTableRequest,
) -> Result<models::ManagedTableResponse, Error<AddDatabaseTableError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_path_schema = schema;
let p_body_add_managed_table_request = add_managed_table_request;
let uri_str = format!(
"{}/v1/databases/{database_id}/schemas/{schema}/tables",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id),
schema = crate::apis::urlencode(p_path_schema)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_add_managed_table_request);
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, req).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::ManagedTableResponse`"))),
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::ManagedTableResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<AddDatabaseTableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Attach an existing connection (catalog) to a database with an optional alias. Inside the database the catalog is reachable as the alias (when set) or its original name.
pub async fn attach_database_catalog(
configuration: &configuration::Configuration,
database_id: &str,
attach_database_catalog_request: models::AttachDatabaseCatalogRequest,
) -> Result<(), Error<AttachDatabaseCatalogError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_body_attach_database_catalog_request = attach_database_catalog_request;
let uri_str = format!(
"{}/v1/databases/{database_id}/catalogs",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_attach_database_catalog_request);
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, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<AttachDatabaseCatalogError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Create many databases from one template in a single request. The databases are created in the background: the response returns immediately with a batch and a job to poll. The databases are not returned inline. List the ones a batch created with `GET /databases?batch=<batch_id>`; they also appear in the normal database listing alongside every other database. Each database gets a default catalog and schema. Declare tables on all of them by passing `schemas`, in the same shape a single create accepts — a batch of 10,000 declaring one table yields 10,000 databases that each hold that table and are ready to load, with no follow-up call per database. Omit `schemas` and the databases are created empty. Either way, load data into them exactly as you would a database created individually.
pub async fn bulk_create_databases(
configuration: &configuration::Configuration,
bulk_create_databases_request: models::BulkCreateDatabasesRequest,
) -> Result<models::DatabaseBatchResponse, Error<BulkCreateDatabasesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_bulk_create_databases_request = bulk_create_databases_request;
let uri_str = format!("{}/v1/databases/bulk", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_bulk_create_databases_request);
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, req).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::DatabaseBatchResponse`"))),
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::DatabaseBatchResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<BulkCreateDatabasesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Return the total number of databases in the workspace. This is the whole-workspace total, not a page size: the `count` field on the listing reports how many rows that one page returned, so totalling a workspace from `GET /v1/databases` means walking every page. Pass `search` to count only databases whose name contains that text (case-insensitive), or `batch` with the `batch_id` returned by a bulk-creation call to count only that batch's databases. The filters mean exactly what they mean on the listing, so a count and a listing given the same filters describe the same set.
pub async fn count_databases(
configuration: &configuration::Configuration,
search: Option<&str>,
batch: Option<&str>,
) -> Result<models::DatabaseCountResponse, Error<CountDatabasesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_search = search;
let p_query_batch = batch;
let uri_str = format!("{}/v1/databases/count", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_search {
req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_batch {
req_builder = req_builder.query(&[("batch", ¶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, req).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::DatabaseCountResponse`"))),
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::DatabaseCountResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<CountDatabasesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Create a new database (a metadata-only grouping). A managed default catalog is auto-created and addressable inside the database as `default` (or the optional `default_catalog` name), with a `main` schema pre-declared so `default.main.<table>` works out of the box. The optional `name` is a free-form display label and is not required to be unique; when omitted, a label derived from the new database's ID is assigned. Optional `default_catalog` overrides the name the default catalog answers to; it must be a valid SQL identifier and may not collide with the reserved catalog names `hotdata` or `information_schema`. Optional `schemas` declares additional schemas/tables on the default catalog at create time; declared tables can be loaded via the standard managed-tables-load endpoint targeting `default_connection_id`. Optional `expires_at` sets when the database expires — accepts either an RFC 3339 timestamp or a relative duration suffixed with `h` (hours), `m` (minutes), or `d` (days), e.g. `24h`, `48h`, `90m`, `7d`. When omitted, the database never expires. Expiry is best-effort: the database will not be deleted before `expires_at`, but cleanup may run later than the exact timestamp. Optional `if_not_exists` makes this a get-or-create: when a database already carries the requested `name`, it is returned with status `200` and nothing is created, which lets a client bind to its database on every start-up without first looking one up.
pub async fn create_database(
configuration: &configuration::Configuration,
create_database_request: models::CreateDatabaseRequest,
) -> Result<models::CreateDatabaseResponse, Error<CreateDatabaseError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_database_request = create_database_request;
let uri_str = format!("{}/v1/databases", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_create_database_request);
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, req).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::CreateDatabaseResponse`"))),
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::CreateDatabaseResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<CreateDatabaseError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Delete a database and its auto-created default catalog. Attached catalogs are detached (their underlying connections are not deleted).
pub async fn delete_database(
configuration: &configuration::Configuration,
database_id: &str,
) -> Result<(), Error<DeleteDatabaseError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let uri_str = format!(
"{}/v1/databases/{database_id}",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
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, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<DeleteDatabaseError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Stop a batch that is still filling and delete the databases it created, then the batch itself. Only batches whose databases hold no data can be removed this way. Tables that were declared but never loaded do not prevent it, so a batch created with `schemas` stays deletable. If any database in the batch has had data loaded into it, the request is rejected and those databases must be deleted one at a time — removing a database that holds data is per-database work that cannot be batched.
pub async fn delete_database_batch(
configuration: &configuration::Configuration,
batch_id: &str,
) -> Result<models::DeleteDatabaseBatchResponse, Error<DeleteDatabaseBatchError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_batch_id = batch_id;
let uri_str = format!(
"{}/v1/databases/bulk/{batch_id}",
configuration.base_path,
batch_id = crate::apis::urlencode(p_path_batch_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
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, req).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::DeleteDatabaseBatchResponse`"))),
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::DeleteDatabaseBatchResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<DeleteDatabaseBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn detach_database_catalog(
configuration: &configuration::Configuration,
database_id: &str,
connection_id: &str,
) -> Result<(), Error<DetachDatabaseCatalogError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_path_connection_id = connection_id;
let uri_str = format!(
"{}/v1/databases/{database_id}/catalogs/{connection_id}",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id),
connection_id = crate::apis::urlencode(p_path_connection_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
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, req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<DetachDatabaseCatalogError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Create a new database that is an independent fork of an existing one. The fork has its own default catalog and contains the same schemas, tables, and data as the source; the source is left unchanged. External catalogs attached to the source are re-attached to the fork. Optional `name` sets the fork's display label; when omitted, the fork takes the source's label followed by a short suffix derived from the fork's own ID, so the two stay distinguishable. Optional `expires_at` sets when the fork expires — accepts an RFC 3339 timestamp or a relative duration suffixed with `h` (hours), `m` (minutes), or `d` (days), e.g. `24h`, `90m`, `7d`. When omitted, a still-future expiry on the source is carried over; otherwise the fork never expires. Any indexes on the source's tables are not carried over.
pub async fn fork_database(
configuration: &configuration::Configuration,
database_id: &str,
fork_database_request: models::ForkDatabaseRequest,
) -> Result<models::CreateDatabaseResponse, Error<ForkDatabaseError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_body_fork_database_request = fork_database_request;
let uri_str = format!(
"{}/v1/databases/{database_id}/fork",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_fork_database_request);
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, req).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::CreateDatabaseResponse`"))),
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::CreateDatabaseResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ForkDatabaseError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Fetch a database by id. The `name` field is a display label only and is not accepted as an identifier here; to fetch a database by its name instead, use `GET /v1/databases/by-name`.
pub async fn get_database(
configuration: &configuration::Configuration,
database_id: &str,
) -> Result<models::DatabaseDetailResponse, Error<GetDatabaseError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let uri_str = format!(
"{}/v1/databases/{database_id}",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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, req).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::DatabaseDetailResponse`"))),
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::DatabaseDetailResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetDatabaseError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Fetch a batch by id: how many databases were requested and how many exist so far. Poll this to follow progress.
pub async fn get_database_batch(
configuration: &configuration::Configuration,
batch_id: &str,
) -> Result<models::DatabaseBatchResponse, Error<GetDatabaseBatchError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_batch_id = batch_id;
let uri_str = format!(
"{}/v1/databases/bulk/{batch_id}",
configuration.base_path,
batch_id = crate::apis::urlencode(p_path_batch_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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, req).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::DatabaseBatchResponse`"))),
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::DatabaseBatchResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetDatabaseBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Trace where a database came from and what came from it. `ancestors` walks the fork chain from this database's immediate source up to the original it descends from, nearest first, and each entry says which state of that source the next database down copied. `forks` lists the databases forked directly from this one, most recently forked first, with `fork_count` giving the true total when the list is only a sample of it. Lineage is a historical record, not a live link: a fork is an independent database from the moment it is created, and either side can change or be deleted without affecting the other. Deleting either one does not erase the record: a deleted ancestor keeps its place in the chain, a deleted fork still appears among `forks`, and both are marked with `exists` set to false. A database that was never forked, and was never forked from, answers with empty lists and itself as `root_id`. Forks taken before lineage was recorded carry none: their provenance was never written and cannot be reconstructed.
pub async fn get_database_lineage(
configuration: &configuration::Configuration,
database_id: &str,
forks_limit: Option<i32>,
) -> Result<models::DatabaseLineageResponse, Error<GetDatabaseLineageError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_query_forks_limit = forks_limit;
let uri_str = format!(
"{}/v1/databases/{database_id}/lineage",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_forks_limit {
req_builder = req_builder.query(&[("forks_limit", ¶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, req).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::DatabaseLineageResponse`"))),
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::DatabaseLineageResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetDatabaseLineageError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// List databases in the workspace, newest first, one page at a time. When no `limit` is given a default page size is applied, so a single call returns at most one page rather than every database. If the response's `has_more` is true, pass its `next_cursor` value back as the `cursor` query parameter to fetch the next page. Pass `search` to return only databases whose name *contains* that text (case-insensitive); to fetch the single database whose name matches exactly, use `GET /v1/databases/by-name` instead. Pass `batch` with the `batch_id` returned by a bulk-creation call to list only that batch's databases.
pub async fn list_databases(
configuration: &configuration::Configuration,
limit: Option<i32>,
cursor: Option<&str>,
search: Option<&str>,
batch: Option<&str>,
) -> Result<models::ListDatabasesResponse, Error<ListDatabasesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_limit = limit;
let p_query_cursor = cursor;
let p_query_search = search;
let p_query_batch = batch;
let uri_str = format!("{}/v1/databases", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
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 param_value) = p_query_search {
req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_batch {
req_builder = req_builder.query(&[("batch", ¶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, req).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::ListDatabasesResponse`"))),
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::ListDatabasesResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ListDatabasesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Publish data as the new contents of a table on the database's default catalog, from one of three sources — provide exactly one. The database-scoped equivalent of the connection-scoped managed-table load — addressed by `database_id`, so no `default_connection_id` is needed. With `data`, CSV text is sent inline in this request, up to 2 MiB; column types are detected from the data unless `columns` declares them, and a larger payload is rejected with 413 and the error code `INLINE_DATA_TOO_LARGE`, at which point the data should be uploaded and loaded by `upload_id` instead. With `upload_id`, a previously-uploaded file is published: CSV, JSON, and Parquet are supported; the format is auto-detected or set via `format`. With `result_id`, a persisted query result is copied into the table, so the table keeps its data even after the result expires. If the target table (or its schema) has not been declared yet, it is created automatically as part of the load — declaring tables up front is optional. `mode` selects how the data is applied: `replace` overwrites the table's contents, `append` inserts the new rows on top of the existing data. Concurrent loads against the same upload return 409. For an upload or inline data, set `async` to run the load in the background and get back a job ID to poll; add `async_after_ms` to wait briefly for it to finish before falling back to a job ID. A `result_id` load runs synchronously.
pub async fn load_database_table(
configuration: &configuration::Configuration,
database_id: &str,
schema: &str,
table: &str,
load_managed_table_request: models::LoadManagedTableRequest,
) -> Result<models::LoadManagedTableResponse, Error<LoadDatabaseTableError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_database_id = database_id;
let p_path_schema = schema;
let p_path_table = table;
let p_body_load_managed_table_request = load_managed_table_request;
let uri_str = format!(
"{}/v1/databases/{database_id}/schemas/{schema}/tables/{table}/loads",
configuration.base_path,
database_id = crate::apis::urlencode(p_path_database_id),
schema = crate::apis::urlencode(p_path_schema),
table = crate::apis::urlencode(p_path_table)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
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);
};
req_builder = req_builder.json(&p_body_load_managed_table_request);
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, req).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::LoadManagedTableResponse`"))),
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::LoadManagedTableResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<LoadDatabaseTableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Fetch a single database by its exact name. This is the counterpart to the listing's `search` filter, which matches any database whose name merely contains the text. Matching ignores case for names made of unaccented Latin letters and digits; that much is guaranteed. For names containing other characters — accented letters, or any non-Latin script — whether case is ignored depends on the deployment, so rely on neither: look those up with the capitalisation they were created with. Returns 404 when no database has that name. A name shared by more than one database returns 409 rather than picking one of them; address those by id.
pub async fn lookup_database_by_name(
configuration: &configuration::Configuration,
name: &str,
) -> Result<models::DatabaseDetailResponse, Error<LookupDatabaseByNameError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_name = name;
let uri_str = format!("{}/v1/databases/by-name", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("name", &p_query_name.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, req).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::DatabaseDetailResponse`"))),
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::DatabaseDetailResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<LookupDatabaseByNameError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}