unitycatalog_client/codegen/functions/
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::functions::v1::*;
12pub struct ListFunctionsBuilder {
14 client: FunctionServiceClient,
15 request: ListFunctionsRequest,
16}
17impl ListFunctionsBuilder {
18 pub(crate) fn new(
21 client: FunctionServiceClient,
22 catalog_name: impl Into<String>,
23 schema_name: impl Into<String>,
24 ) -> Self {
25 let request = ListFunctionsRequest {
26 catalog_name: catalog_name.into(),
27 schema_name: schema_name.into(),
28 ..Default::default()
29 };
30 Self { client, request }
31 }
32 pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
34 self.request.max_results = max_results.into();
35 self
36 }
37 pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
39 self.request.page_token = page_token.into();
40 self
41 }
42 pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
44 self.request.include_browse = include_browse.into();
45 self
46 }
47 pub fn into_stream(self) -> BoxStr<'static, Result<Function>> {
49 let remaining = self.request.max_results;
50 let stream = stream_paginated(
51 (self, remaining),
52 move |(mut builder, mut remaining), page_token| async move {
53 builder.request.page_token = page_token;
54 let res = builder.client.list_functions(&builder.request).await?;
55 if let Some(ref mut rem) = remaining {
56 *rem -= res.functions.len() as i32;
57 }
58 let next_page_token = if remaining.is_some_and(|r| r <= 0) {
59 None
60 } else {
61 res.next_page_token.clone()
62 };
63 Ok((res, (builder, remaining), next_page_token))
64 },
65 )
66 .map_ok(|resp| futures::stream::iter(resp.functions.into_iter().map(Ok)))
67 .try_flatten();
68 stream.boxed()
69 }
70}
71impl IntoFuture for ListFunctionsBuilder {
72 type Output = Result<ListFunctionsResponse>;
73 type IntoFuture = BoxFut<'static, Self::Output>;
74 fn into_future(self) -> Self::IntoFuture {
75 let client = self.client;
76 let request = self.request;
77 Box::pin(async move { client.list_functions(&request).await })
78 }
79}
80pub struct CreateFunctionBuilder {
82 client: FunctionServiceClient,
83 request: CreateFunctionRequest,
84}
85impl CreateFunctionBuilder {
86 pub(crate) fn new(
89 client: FunctionServiceClient,
90 name: impl Into<String>,
91 catalog_name: impl Into<String>,
92 schema_name: impl Into<String>,
93 data_type: impl Into<String>,
94 full_data_type: impl Into<String>,
95 parameter_style: ParameterStyle,
96 is_deterministic: bool,
97 sql_data_access: SqlDataAccess,
98 is_null_call: bool,
99 security_type: SecurityType,
100 routine_body: RoutineBody,
101 ) -> Self {
102 let request = CreateFunctionRequest {
103 name: name.into(),
104 catalog_name: catalog_name.into(),
105 schema_name: schema_name.into(),
106 data_type: data_type.into(),
107 full_data_type: full_data_type.into(),
108 parameter_style: parameter_style as i32,
109 is_deterministic,
110 sql_data_access: sql_data_access as i32,
111 is_null_call,
112 security_type: security_type as i32,
113 routine_body: routine_body as i32,
114 ..Default::default()
115 };
116 Self { client, request }
117 }
118 pub fn with_input_params(
120 mut self,
121 input_params: impl Into<Option<FunctionParameterInfos>>,
122 ) -> Self {
123 self.request.input_params = input_params.into();
124 self
125 }
126 pub fn with_routine_definition(
128 mut self,
129 routine_definition: impl Into<Option<String>>,
130 ) -> Self {
131 self.request.routine_definition = routine_definition.into();
132 self
133 }
134 pub fn with_routine_body_language(
136 mut self,
137 routine_body_language: impl Into<Option<String>>,
138 ) -> Self {
139 self.request.routine_body_language = routine_body_language.into();
140 self
141 }
142 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
144 self.request.comment = comment.into();
145 self
146 }
147 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
149 where
150 I: IntoIterator<Item = (K, V)>,
151 K: Into<String>,
152 V: Into<String>,
153 {
154 self.request.properties = properties
155 .into_iter()
156 .map(|(k, v)| (k.into(), v.into()))
157 .collect();
158 self
159 }
160}
161impl IntoFuture for CreateFunctionBuilder {
162 type Output = Result<Function>;
163 type IntoFuture = BoxFut<'static, Self::Output>;
164 fn into_future(self) -> Self::IntoFuture {
165 let client = self.client;
166 let request = self.request;
167 Box::pin(async move { client.create_function(&request).await })
168 }
169}
170pub struct GetFunctionBuilder {
172 client: FunctionServiceClient,
173 request: GetFunctionRequest,
174}
175impl GetFunctionBuilder {
176 pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
179 let request = GetFunctionRequest { name: name.into() };
180 Self { client, request }
181 }
182}
183impl IntoFuture for GetFunctionBuilder {
184 type Output = Result<Function>;
185 type IntoFuture = BoxFut<'static, Self::Output>;
186 fn into_future(self) -> Self::IntoFuture {
187 let client = self.client;
188 let request = self.request;
189 Box::pin(async move { client.get_function(&request).await })
190 }
191}
192pub struct UpdateFunctionBuilder {
194 client: FunctionServiceClient,
195 request: UpdateFunctionRequest,
196}
197impl UpdateFunctionBuilder {
198 pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
201 let request = UpdateFunctionRequest {
202 name: name.into(),
203 ..Default::default()
204 };
205 Self { client, request }
206 }
207 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
209 self.request.owner = owner.into();
210 self
211 }
212}
213impl IntoFuture for UpdateFunctionBuilder {
214 type Output = Result<Function>;
215 type IntoFuture = BoxFut<'static, Self::Output>;
216 fn into_future(self) -> Self::IntoFuture {
217 let client = self.client;
218 let request = self.request;
219 Box::pin(async move { client.update_function(&request).await })
220 }
221}
222pub struct DeleteFunctionBuilder {
224 client: FunctionServiceClient,
225 request: DeleteFunctionRequest,
226}
227impl DeleteFunctionBuilder {
228 pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
231 let request = DeleteFunctionRequest {
232 name: name.into(),
233 ..Default::default()
234 };
235 Self { client, request }
236 }
237 pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
239 self.request.force = force.into();
240 self
241 }
242}
243impl IntoFuture for DeleteFunctionBuilder {
244 type Output = Result<()>;
245 type IntoFuture = BoxFut<'static, Self::Output>;
246 fn into_future(self) -> Self::IntoFuture {
247 let client = self.client;
248 let request = self.request;
249 Box::pin(async move { client.delete_function(&request).await })
250 }
251}