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