unitycatalog_client/codegen/schemas/
builders.rs1#![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::*;
18pub struct ListSchemasBuilder {
20 client: SchemaServiceClient,
21 request: ListSchemasRequest,
22}
23impl ListSchemasBuilder {
24 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 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 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 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 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}
85pub struct CreateSchemaBuilder {
87 client: SchemaServiceClient,
88 request: CreateSchemaRequest,
89}
90impl CreateSchemaBuilder {
91 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
107 self.request.comment = comment.into();
108 self
109 }
110 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 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}
141pub struct GetSchemaBuilder {
143 client: SchemaServiceClient,
144 request: GetSchemaRequest,
145}
146impl GetSchemaBuilder {
147 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}
166pub struct UpdateSchemaBuilder {
168 client: SchemaServiceClient,
169 request: UpdateSchemaRequest,
170}
171impl UpdateSchemaBuilder {
172 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
183 self.request.comment = comment.into();
184 self
185 }
186 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 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}
217pub struct DeleteSchemaBuilder {
219 client: SchemaServiceClient,
220 request: DeleteSchemaRequest,
221}
222impl DeleteSchemaBuilder {
223 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 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}