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