Skip to main content

unitycatalog_client/codegen/catalogs/
builders.rs

1// @generated — do not edit by hand.
2#![allow(unused_mut)]
3#![allow(unused_imports)]
4#[cfg(not(target_arch = "wasm32"))]
5type BoxFut<'a, T> = ::futures::future::BoxFuture<'a, T>;
6#[cfg(target_arch = "wasm32")]
7type BoxFut<'a, T> = ::futures::future::LocalBoxFuture<'a, T>;
8#[cfg(not(target_arch = "wasm32"))]
9type BoxStr<'a, T> = ::futures::stream::BoxStream<'a, T>;
10#[cfg(target_arch = "wasm32")]
11type BoxStr<'a, T> = ::futures::stream::LocalBoxStream<'a, T>;
12use super::super::stream_paginated;
13use super::client::*;
14use crate::Result;
15use futures::{StreamExt, TryStreamExt};
16use std::future::IntoFuture;
17use unitycatalog_common::models::catalogs::v1::*;
18/// Builder for listing catalogs
19pub struct ListCatalogsBuilder {
20    client: CatalogServiceClient,
21    request: ListCatalogsRequest,
22}
23impl ListCatalogsBuilder {
24    /// Create a new builder instance.
25    /// Obtain via the corresponding method on `CatalogServiceClient`.
26    pub(crate) fn new(client: CatalogServiceClient) -> Self {
27        let request = ListCatalogsRequest {
28            ..Default::default()
29        };
30        Self { client, request }
31    }
32    /// The maximum number of results per page that should be returned.
33    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
34        self.request.max_results = max_results.into();
35        self
36    }
37    /// Opaque pagination token to go to next page based on previous query.
38    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
39        self.request.page_token = page_token.into();
40        self
41    }
42    /// Convert paginated request into stream of results
43    pub fn into_stream(self) -> BoxStr<'static, Result<Catalog>> {
44        let remaining = self.request.max_results;
45        let stream = stream_paginated(
46            (self, remaining),
47            move |(mut builder, mut remaining), page_token| async move {
48                builder.request.page_token = page_token;
49                let res = builder.client.list_catalogs(&builder.request).await?;
50                if let Some(ref mut rem) = remaining {
51                    *rem -= res.catalogs.len() as i32;
52                }
53                let next_page_token = if remaining.is_some_and(|r| r <= 0) {
54                    None
55                } else {
56                    res.next_page_token.clone()
57                };
58                Ok((res, (builder, remaining), next_page_token))
59            },
60        )
61        .map_ok(|resp| futures::stream::iter(resp.catalogs.into_iter().map(Ok)))
62        .try_flatten();
63        #[cfg(not(target_arch = "wasm32"))]
64        let stream = stream.boxed();
65        #[cfg(target_arch = "wasm32")]
66        let stream = stream.boxed_local();
67        stream
68    }
69}
70impl IntoFuture for ListCatalogsBuilder {
71    type Output = Result<ListCatalogsResponse>;
72    type IntoFuture = BoxFut<'static, Self::Output>;
73    fn into_future(self) -> Self::IntoFuture {
74        let client = self.client;
75        let request = self.request;
76        Box::pin(async move { client.list_catalogs(&request).await })
77    }
78}
79/// Builder for creating a catalog
80pub struct CreateCatalogBuilder {
81    client: CatalogServiceClient,
82    request: CreateCatalogRequest,
83}
84impl CreateCatalogBuilder {
85    /// Create a new builder instance.
86    /// Obtain via the corresponding method on `CatalogServiceClient`.
87    pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
88        let request = CreateCatalogRequest {
89            name: name.into(),
90            ..Default::default()
91        };
92        Self { client, request }
93    }
94    /// User-provided free-form text description.
95    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
96        self.request.comment = comment.into();
97        self
98    }
99    /// A map of key-value properties attached to the securable.
100    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
101    where
102        I: IntoIterator<Item = (K, V)>,
103        K: Into<String>,
104        V: Into<String>,
105    {
106        self.request.properties = properties
107            .into_iter()
108            .map(|(k, v)| (k.into(), v.into()))
109            .collect();
110        self
111    }
112    /// Storage root URL for managed tables within catalog.
113    pub fn with_storage_root(mut self, storage_root: impl Into<Option<String>>) -> Self {
114        self.request.storage_root = storage_root.into();
115        self
116    }
117    /** The name of delta sharing provider.
118
119    A Delta Sharing catalog is a catalog that is based on a Delta share on a remote sharing server.*/
120    pub fn with_provider_name(mut self, provider_name: impl Into<Option<String>>) -> Self {
121        self.request.provider_name = provider_name.into();
122        self
123    }
124    /// The name of the share under the share provider.
125    pub fn with_share_name(mut self, share_name: impl Into<Option<String>>) -> Self {
126        self.request.share_name = share_name.into();
127        self
128    }
129}
130impl IntoFuture for CreateCatalogBuilder {
131    type Output = Result<Catalog>;
132    type IntoFuture = BoxFut<'static, Self::Output>;
133    fn into_future(self) -> Self::IntoFuture {
134        let client = self.client;
135        let request = self.request;
136        Box::pin(async move { client.create_catalog(&request).await })
137    }
138}
139/// Builder for getting a catalog
140pub struct GetCatalogBuilder {
141    client: CatalogServiceClient,
142    request: GetCatalogRequest,
143}
144impl GetCatalogBuilder {
145    /// Create a new builder instance.
146    /// Obtain via the corresponding method on `CatalogServiceClient`.
147    pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
148        let request = GetCatalogRequest {
149            name: name.into(),
150            ..Default::default()
151        };
152        Self { client, request }
153    }
154    /// Whether to include catalogs in the response for which the principal can only access selective metadata for
155    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
156        self.request.include_browse = include_browse.into();
157        self
158    }
159}
160impl IntoFuture for GetCatalogBuilder {
161    type Output = Result<Catalog>;
162    type IntoFuture = BoxFut<'static, Self::Output>;
163    fn into_future(self) -> Self::IntoFuture {
164        let client = self.client;
165        let request = self.request;
166        Box::pin(async move { client.get_catalog(&request).await })
167    }
168}
169/// Builder for updating a catalog
170pub struct UpdateCatalogBuilder {
171    client: CatalogServiceClient,
172    request: UpdateCatalogRequest,
173}
174impl UpdateCatalogBuilder {
175    /// Create a new builder instance.
176    /// Obtain via the corresponding method on `CatalogServiceClient`.
177    pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
178        let request = UpdateCatalogRequest {
179            name: name.into(),
180            ..Default::default()
181        };
182        Self { client, request }
183    }
184    /// Username of new owner of catalog.
185    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
186        self.request.owner = owner.into();
187        self
188    }
189    /// User-provided free-form text description.
190    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
191        self.request.comment = comment.into();
192        self
193    }
194    /** A map of key-value properties attached to the securable.
195
196    When provided in update request, the specified properties will override the existing properties.
197    To add and remove properties, one would need to perform a read-modify-write.*/
198    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
199    where
200        I: IntoIterator<Item = (K, V)>,
201        K: Into<String>,
202        V: Into<String>,
203    {
204        self.request.properties = properties
205            .into_iter()
206            .map(|(k, v)| (k.into(), v.into()))
207            .collect();
208        self
209    }
210    /// Name of catalog.
211    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
212        self.request.new_name = new_name.into();
213        self
214    }
215}
216impl IntoFuture for UpdateCatalogBuilder {
217    type Output = Result<Catalog>;
218    type IntoFuture = BoxFut<'static, Self::Output>;
219    fn into_future(self) -> Self::IntoFuture {
220        let client = self.client;
221        let request = self.request;
222        Box::pin(async move { client.update_catalog(&request).await })
223    }
224}
225/// Builder for deleting a catalog
226pub struct DeleteCatalogBuilder {
227    client: CatalogServiceClient,
228    request: DeleteCatalogRequest,
229}
230impl DeleteCatalogBuilder {
231    /// Create a new builder instance.
232    /// Obtain via the corresponding method on `CatalogServiceClient`.
233    pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
234        let request = DeleteCatalogRequest {
235            name: name.into(),
236            ..Default::default()
237        };
238        Self { client, request }
239    }
240    /// Force deletion even if the catalog is not empty.
241    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
242        self.request.force = force.into();
243        self
244    }
245}
246impl IntoFuture for DeleteCatalogBuilder {
247    type Output = Result<()>;
248    type IntoFuture = BoxFut<'static, Self::Output>;
249    fn into_future(self) -> Self::IntoFuture {
250        let client = self.client;
251        let request = self.request;
252        Box::pin(async move { client.delete_catalog(&request).await })
253    }
254}