Skip to main content

unitycatalog_client/codegen/schemas/
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::schemas::v1::*;
12/// Builder for listing schemas
13pub struct ListSchemasBuilder {
14    client: SchemaServiceClient,
15    request: ListSchemasRequest,
16}
17impl ListSchemasBuilder {
18    /// Create a new builder instance.
19    /// Obtain via the corresponding method on `SchemaServiceClient`.
20    pub(crate) fn new(client: SchemaServiceClient, catalog_name: impl Into<String>) -> Self {
21        let request = ListSchemasRequest {
22            catalog_name: catalog_name.into(),
23            ..Default::default()
24        };
25        Self { client, request }
26    }
27    /// The maximum number of results per page that should be returned.
28    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
29        self.request.max_results = max_results.into();
30        self
31    }
32    /// Opaque pagination token to go to next page based on previous query.
33    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
34        self.request.page_token = page_token.into();
35        self
36    }
37    /// Whether to include schemas in the response for which the principal can only access selective metadata for
38    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
39        self.request.include_browse = include_browse.into();
40        self
41    }
42    /// Convert paginated request into stream of results
43    pub fn into_stream(self) -> BoxStr<'static, Result<Schema>> {
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_schemas(&builder.request).await?;
50                if let Some(ref mut rem) = remaining {
51                    *rem -= res.schemas.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.schemas.into_iter().map(Ok)))
62        .try_flatten();
63        stream.boxed()
64    }
65}
66impl IntoFuture for ListSchemasBuilder {
67    type Output = Result<ListSchemasResponse>;
68    type IntoFuture = BoxFut<'static, Self::Output>;
69    fn into_future(self) -> Self::IntoFuture {
70        let client = self.client;
71        let request = self.request;
72        Box::pin(async move { client.list_schemas(&request).await })
73    }
74}
75/// Builder for creating a schema
76pub struct CreateSchemaBuilder {
77    client: SchemaServiceClient,
78    request: CreateSchemaRequest,
79}
80impl CreateSchemaBuilder {
81    /// Create a new builder instance.
82    /// Obtain via the corresponding method on `SchemaServiceClient`.
83    pub(crate) fn new(
84        client: SchemaServiceClient,
85        name: impl Into<String>,
86        catalog_name: impl Into<String>,
87    ) -> Self {
88        let request = CreateSchemaRequest {
89            name: name.into(),
90            catalog_name: catalog_name.into(),
91            ..Default::default()
92        };
93        Self { client, request }
94    }
95    /// User-provided free-form text description.
96    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
97        self.request.comment = comment.into();
98        self
99    }
100    /// A map of key-value properties attached to the securable.
101    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
102    where
103        I: IntoIterator<Item = (K, V)>,
104        K: Into<String>,
105        V: Into<String>,
106    {
107        self.request.properties = properties
108            .into_iter()
109            .map(|(k, v)| (k.into(), v.into()))
110            .collect();
111        self
112    }
113    /** Storage root URL for managed storage location of the schema.
114
115    If not set, managed securables under this schema fall back to the parent
116    catalog's storage location. Example: `s3://bucket/ucroot`.*/
117    pub fn with_storage_root(mut self, storage_root: impl Into<Option<String>>) -> Self {
118        self.request.storage_root = storage_root.into();
119        self
120    }
121}
122impl IntoFuture for CreateSchemaBuilder {
123    type Output = Result<Schema>;
124    type IntoFuture = BoxFut<'static, Self::Output>;
125    fn into_future(self) -> Self::IntoFuture {
126        let client = self.client;
127        let request = self.request;
128        Box::pin(async move { client.create_schema(&request).await })
129    }
130}
131/// Builder for getting a schema
132pub struct GetSchemaBuilder {
133    client: SchemaServiceClient,
134    request: GetSchemaRequest,
135}
136impl GetSchemaBuilder {
137    /// Create a new builder instance.
138    /// Obtain via the corresponding method on `SchemaServiceClient`.
139    pub(crate) fn new(client: SchemaServiceClient, full_name: impl Into<String>) -> Self {
140        let request = GetSchemaRequest {
141            full_name: full_name.into(),
142            ..Default::default()
143        };
144        Self { client, request }
145    }
146}
147impl IntoFuture for GetSchemaBuilder {
148    type Output = Result<Schema>;
149    type IntoFuture = BoxFut<'static, Self::Output>;
150    fn into_future(self) -> Self::IntoFuture {
151        let client = self.client;
152        let request = self.request;
153        Box::pin(async move { client.get_schema(&request).await })
154    }
155}
156/// Builder for updating a schema
157pub struct UpdateSchemaBuilder {
158    client: SchemaServiceClient,
159    request: UpdateSchemaRequest,
160}
161impl UpdateSchemaBuilder {
162    /// Create a new builder instance.
163    /// Obtain via the corresponding method on `SchemaServiceClient`.
164    pub(crate) fn new(client: SchemaServiceClient, full_name: impl Into<String>) -> Self {
165        let request = UpdateSchemaRequest {
166            full_name: full_name.into(),
167            ..Default::default()
168        };
169        Self { client, request }
170    }
171    /// User-provided free-form text description.
172    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
173        self.request.comment = comment.into();
174        self
175    }
176    /** A map of key-value properties attached to the securable.
177
178    When provided in update request, the specified properties will override the existing properties.
179    To add and remove properties, one would need to perform a read-modify-write.*/
180    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
181    where
182        I: IntoIterator<Item = (K, V)>,
183        K: Into<String>,
184        V: Into<String>,
185    {
186        self.request.properties = properties
187            .into_iter()
188            .map(|(k, v)| (k.into(), v.into()))
189            .collect();
190        self
191    }
192    /// Name of schema.
193    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
194        self.request.new_name = new_name.into();
195        self
196    }
197}
198impl IntoFuture for UpdateSchemaBuilder {
199    type Output = Result<Schema>;
200    type IntoFuture = BoxFut<'static, Self::Output>;
201    fn into_future(self) -> Self::IntoFuture {
202        let client = self.client;
203        let request = self.request;
204        Box::pin(async move { client.update_schema(&request).await })
205    }
206}
207/// Builder for deleting a schema
208pub struct DeleteSchemaBuilder {
209    client: SchemaServiceClient,
210    request: DeleteSchemaRequest,
211}
212impl DeleteSchemaBuilder {
213    /// Create a new builder instance.
214    /// Obtain via the corresponding method on `SchemaServiceClient`.
215    pub(crate) fn new(client: SchemaServiceClient, full_name: impl Into<String>) -> Self {
216        let request = DeleteSchemaRequest {
217            full_name: full_name.into(),
218            ..Default::default()
219        };
220        Self { client, request }
221    }
222    /// Force deletion even if the schema is not empty.
223    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
224        self.request.force = force.into();
225        self
226    }
227}
228impl IntoFuture for DeleteSchemaBuilder {
229    type Output = Result<()>;
230    type IntoFuture = BoxFut<'static, Self::Output>;
231    fn into_future(self) -> Self::IntoFuture {
232        let client = self.client;
233        let request = self.request;
234        Box::pin(async move { client.delete_schema(&request).await })
235    }
236}