unitycatalog_client/codegen/schemas/
client.rs1#![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#[derive(Clone)]
12pub struct SchemaServiceClient {
13 pub(crate) client: Transport,
14 pub(crate) base_url: Url,
15}
16impl SchemaServiceClient {
17 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 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 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 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 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 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}