Skip to main content

unitycatalog_client/codegen/schemas/
client.rs

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