Skip to main content

unitycatalog_client/codegen/schemas/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4#[cfg(not(target_arch = "wasm32"))]
5use ::olai_http::CloudClient as Transport;
6#[cfg(target_arch = "wasm32")]
7use ::olai_http_wasm::WasmClient as Transport;
8use unitycatalog_common::models::schemas::v1::*;
9use url::Url;
10/// HTTP client for service operations
11#[derive(Clone)]
12pub struct SchemaServiceClient {
13    pub(crate) client: Transport,
14    pub(crate) base_url: Url,
15}
16impl SchemaServiceClient {
17    /// Create a new client instance
18    pub fn new(client: Transport, mut base_url: Url) -> Self {
19        if !base_url.path().ends_with('/') {
20            base_url.set_path(&format!("{}/", base_url.path()));
21        }
22        Self { client, base_url }
23    }
24    /// Gets an array of schemas for a catalog in the metastore. If the caller is the metastore
25    /// admin or the owner of the parent catalog, all schemas for the catalog will be retrieved.
26    /// Otherwise, only schemas owned by the caller (or for which the caller has the USE_SCHEMA privilege)
27    /// will be retrieved. There is no guarantee of a specific ordering of the elements in the array.
28    pub async fn list_schemas(&self, request: &ListSchemasRequest) -> Result<ListSchemasResponse> {
29        let mut url = self.base_url.join("schemas")?;
30        url.query_pairs_mut()
31            .append_pair("catalog_name", &request.catalog_name);
32        if let Some(ref value) = request.max_results {
33            url.query_pairs_mut()
34                .append_pair("max_results", &value.to_string());
35        }
36        if let Some(ref value) = request.page_token {
37            url.query_pairs_mut()
38                .append_pair("page_token", &value.to_string());
39        }
40        if let Some(ref value) = request.include_browse {
41            url.query_pairs_mut()
42                .append_pair("include_browse", &value.to_string());
43        }
44        let response = self.client.get(url).send().await?;
45        if !response.status().is_success() {
46            return Err(crate::error::parse_error_response(response).await);
47        }
48        let result = response.bytes().await?;
49        Ok(serde_json::from_slice(&result)?)
50    }
51    /// Creates a new schema for catalog in the Metatastore. The caller must be a metastore admin,
52    /// or have the CREATE_SCHEMA privilege in the parent catalog.
53    pub async fn create_schema(&self, request: &CreateSchemaRequest) -> Result<Schema> {
54        let url = self.base_url.join("schemas")?;
55        let response = self.client.post(url).json(request).send().await?;
56        if !response.status().is_success() {
57            return Err(crate::error::parse_error_response(response).await);
58        }
59        let result = response.bytes().await?;
60        Ok(serde_json::from_slice(&result)?)
61    }
62    /// Gets the specified schema within the metastore.
63    /// The caller must be a metastore admin, the owner of the schema,
64    /// or a user that has the USE_SCHEMA privilege on the schema.
65    pub async fn get_schema(&self, request: &GetSchemaRequest) -> Result<Schema> {
66        let formatted_path = format!("schemas/{}", request.full_name);
67        let url = self.base_url.join(&formatted_path)?;
68        let response = self.client.get(url).send().await?;
69        if !response.status().is_success() {
70            return Err(crate::error::parse_error_response(response).await);
71        }
72        let result = response.bytes().await?;
73        Ok(serde_json::from_slice(&result)?)
74    }
75    /// Updates a schema for a catalog. The caller must be the owner of the schema or a metastore admin.
76    /// If the caller is a metastore admin, only the owner field can be changed in the update.
77    /// If the name field must be updated, the caller must be a metastore admin or have the CREATE_SCHEMA
78    /// privilege on the parent catalog.
79    pub async fn update_schema(&self, request: &UpdateSchemaRequest) -> Result<Schema> {
80        let formatted_path = format!("schemas/{}", request.full_name);
81        let url = self.base_url.join(&formatted_path)?;
82        let response = self.client.patch(url).json(request).send().await?;
83        if !response.status().is_success() {
84            return Err(crate::error::parse_error_response(response).await);
85        }
86        let result = response.bytes().await?;
87        Ok(serde_json::from_slice(&result)?)
88    }
89    /// Deletes the specified schema from the parent catalog. The caller must be the owner
90    /// of the schema or an owner of the parent catalog.
91    pub async fn delete_schema(&self, request: &DeleteSchemaRequest) -> Result<()> {
92        let formatted_path = format!("schemas/{}", request.full_name);
93        let mut url = self.base_url.join(&formatted_path)?;
94        if let Some(ref value) = request.force {
95            url.query_pairs_mut()
96                .append_pair("force", &value.to_string());
97        }
98        let response = self.client.delete(url).send().await?;
99        if !response.status().is_success() {
100            return Err(crate::error::parse_error_response(response).await);
101        }
102        Ok(())
103    }
104}