unitycatalog_client/codegen/schemas/
builders.rs1#![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::*;
12pub struct ListSchemasBuilder {
14 client: SchemaServiceClient,
15 request: ListSchemasRequest,
16}
17impl ListSchemasBuilder {
18 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 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 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 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 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}
75pub struct CreateSchemaBuilder {
77 client: SchemaServiceClient,
78 request: CreateSchemaRequest,
79}
80impl CreateSchemaBuilder {
81 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
97 self.request.comment = comment.into();
98 self
99 }
100 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 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}
131pub struct GetSchemaBuilder {
133 client: SchemaServiceClient,
134 request: GetSchemaRequest,
135}
136impl GetSchemaBuilder {
137 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}
156pub struct UpdateSchemaBuilder {
158 client: SchemaServiceClient,
159 request: UpdateSchemaRequest,
160}
161impl UpdateSchemaBuilder {
162 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
173 self.request.comment = comment.into();
174 self
175 }
176 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 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}
207pub struct DeleteSchemaBuilder {
209 client: SchemaServiceClient,
210 request: DeleteSchemaRequest,
211}
212impl DeleteSchemaBuilder {
213 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 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}