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        };
143        Self { client, request }
144    }
145}
146impl IntoFuture for GetSchemaBuilder {
147    type Output = Result<Schema>;
148    type IntoFuture = BoxFut<'static, Self::Output>;
149    fn into_future(self) -> Self::IntoFuture {
150        let client = self.client;
151        let request = self.request;
152        Box::pin(async move { client.get_schema(&request).await })
153    }
154}
155/// Builder for updating a schema
156pub struct UpdateSchemaBuilder {
157    client: SchemaServiceClient,
158    request: UpdateSchemaRequest,
159}
160impl UpdateSchemaBuilder {
161    /// Create a new builder instance.
162    /// Obtain via the corresponding method on `SchemaServiceClient`.
163    pub(crate) fn new(client: SchemaServiceClient, full_name: impl Into<String>) -> Self {
164        let request = UpdateSchemaRequest {
165            full_name: full_name.into(),
166            ..Default::default()
167        };
168        Self { client, request }
169    }
170    /// User-provided free-form text description.
171    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
172        self.request.comment = comment.into();
173        self
174    }
175    /** A map of key-value properties attached to the securable.
176
177    When provided in update request, the specified properties will override the existing properties.
178    To add and remove properties, one would need to perform a read-modify-write.*/
179    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
180    where
181        I: IntoIterator<Item = (K, V)>,
182        K: Into<String>,
183        V: Into<String>,
184    {
185        self.request.properties = properties
186            .into_iter()
187            .map(|(k, v)| (k.into(), v.into()))
188            .collect();
189        self
190    }
191    /// Name of schema.
192    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
193        self.request.new_name = new_name.into();
194        self
195    }
196}
197impl IntoFuture for UpdateSchemaBuilder {
198    type Output = Result<Schema>;
199    type IntoFuture = BoxFut<'static, Self::Output>;
200    fn into_future(self) -> Self::IntoFuture {
201        let client = self.client;
202        let request = self.request;
203        Box::pin(async move { client.update_schema(&request).await })
204    }
205}
206/// Builder for deleting a schema
207pub struct DeleteSchemaBuilder {
208    client: SchemaServiceClient,
209    request: DeleteSchemaRequest,
210}
211impl DeleteSchemaBuilder {
212    /// Create a new builder instance.
213    /// Obtain via the corresponding method on `SchemaServiceClient`.
214    pub(crate) fn new(client: SchemaServiceClient, full_name: impl Into<String>) -> Self {
215        let request = DeleteSchemaRequest {
216            full_name: full_name.into(),
217            ..Default::default()
218        };
219        Self { client, request }
220    }
221    /// Force deletion even if the schema is not empty.
222    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
223        self.request.force = force.into();
224        self
225    }
226}
227impl IntoFuture for DeleteSchemaBuilder {
228    type Output = Result<()>;
229    type IntoFuture = BoxFut<'static, Self::Output>;
230    fn into_future(self) -> Self::IntoFuture {
231        let client = self.client;
232        let request = self.request;
233        Box::pin(async move { client.delete_schema(&request).await })
234    }
235}