Skip to main content

unitycatalog_client/codegen/functions/
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::functions::v1::*;
12/// Builder for listing functions
13pub struct ListFunctionsBuilder {
14    client: FunctionServiceClient,
15    request: ListFunctionsRequest,
16}
17impl ListFunctionsBuilder {
18    /// Create a new builder instance.
19    /// Obtain via the corresponding method on `FunctionServiceClient`.
20    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    /// The maximum number of results per page that should be returned.
33    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    /// Opaque pagination token to go to next page based on previous query.
38    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    /// Whether to include functions in the response for which the principal can only access selective metadata for.
43    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    /// Convert paginated request into stream of results
48    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}
80/// Builder for creating a function
81pub struct CreateFunctionBuilder {
82    client: FunctionServiceClient,
83    request: CreateFunctionRequest,
84}
85impl CreateFunctionBuilder {
86    /// Create a new builder instance.
87    /// Obtain via the corresponding method on `FunctionServiceClient`.
88    pub(crate) fn new(client: FunctionServiceClient, function_info: CreateFunction) -> Self {
89        let request = CreateFunctionRequest {
90            function_info: buffa::MessageField::some(function_info),
91            ..Default::default()
92        };
93        Self { client, request }
94    }
95}
96impl IntoFuture for CreateFunctionBuilder {
97    type Output = Result<Function>;
98    type IntoFuture = BoxFut<'static, Self::Output>;
99    fn into_future(self) -> Self::IntoFuture {
100        let client = self.client;
101        let request = self.request;
102        Box::pin(async move { client.create_function(&request).await })
103    }
104}
105/// Builder for getting a function
106pub struct GetFunctionBuilder {
107    client: FunctionServiceClient,
108    request: GetFunctionRequest,
109}
110impl GetFunctionBuilder {
111    /// Create a new builder instance.
112    /// Obtain via the corresponding method on `FunctionServiceClient`.
113    pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
114        let request = GetFunctionRequest {
115            name: name.into(),
116            ..Default::default()
117        };
118        Self { client, request }
119    }
120}
121impl IntoFuture for GetFunctionBuilder {
122    type Output = Result<Function>;
123    type IntoFuture = BoxFut<'static, Self::Output>;
124    fn into_future(self) -> Self::IntoFuture {
125        let client = self.client;
126        let request = self.request;
127        Box::pin(async move { client.get_function(&request).await })
128    }
129}
130/// Builder for updating a function
131pub struct UpdateFunctionBuilder {
132    client: FunctionServiceClient,
133    request: UpdateFunctionRequest,
134}
135impl UpdateFunctionBuilder {
136    /// Create a new builder instance.
137    /// Obtain via the corresponding method on `FunctionServiceClient`.
138    pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
139        let request = UpdateFunctionRequest {
140            name: name.into(),
141            ..Default::default()
142        };
143        Self { client, request }
144    }
145    /// Username of new owner of the function.
146    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
147        self.request.owner = owner.into();
148        self
149    }
150}
151impl IntoFuture for UpdateFunctionBuilder {
152    type Output = Result<Function>;
153    type IntoFuture = BoxFut<'static, Self::Output>;
154    fn into_future(self) -> Self::IntoFuture {
155        let client = self.client;
156        let request = self.request;
157        Box::pin(async move { client.update_function(&request).await })
158    }
159}
160/// Builder for deleting a function
161pub struct DeleteFunctionBuilder {
162    client: FunctionServiceClient,
163    request: DeleteFunctionRequest,
164}
165impl DeleteFunctionBuilder {
166    /// Create a new builder instance.
167    /// Obtain via the corresponding method on `FunctionServiceClient`.
168    pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
169        let request = DeleteFunctionRequest {
170            name: name.into(),
171            ..Default::default()
172        };
173        Self { client, request }
174    }
175    /// Force deletion even if the function is not empty.
176    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
177        self.request.force = force.into();
178        self
179    }
180}
181impl IntoFuture for DeleteFunctionBuilder {
182    type Output = Result<()>;
183    type IntoFuture = BoxFut<'static, Self::Output>;
184    fn into_future(self) -> Self::IntoFuture {
185        let client = self.client;
186        let request = self.request;
187        Box::pin(async move { client.delete_function(&request).await })
188    }
189}