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 };
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}
155pub struct UpdateSchemaBuilder {
157 client: SchemaServiceClient,
158 request: UpdateSchemaRequest,
159}
160impl UpdateSchemaBuilder {
161 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
172 self.request.comment = comment.into();
173 self
174 }
175 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 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}
206pub struct DeleteSchemaBuilder {
208 client: SchemaServiceClient,
209 request: DeleteSchemaRequest,
210}
211impl DeleteSchemaBuilder {
212 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 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}