Skip to main content

lance_namespace_reqwest_client/apis/
branch_api.rs

1/*
2 * Lance Namespace Specification
3 *
4 * This OpenAPI specification is a part of the Lance namespace specification. It contains 2 parts:  The `components/schemas`, `components/responses`, `components/examples`, `tags` sections define the request and response shape for each operation in a Lance Namespace across all implementations. See https://lance.org/format/namespace/operations for more details.  The `servers`, `security`, `paths`, `components/parameters` sections are for the Lance REST Namespace implementation, which defines a complete REST server that can work with Lance datasets. See https://lance.org/format/namespace/rest for more details. 
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`create_table_branch`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateTableBranchError {
22    Status400(models::ErrorResponse),
23    Status401(models::ErrorResponse),
24    Status403(models::ErrorResponse),
25    Status404(models::ErrorResponse),
26    Status409(models::ErrorResponse),
27    Status503(models::ErrorResponse),
28    Status5XX(models::ErrorResponse),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`delete_table_branch`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DeleteTableBranchError {
36    Status400(models::ErrorResponse),
37    Status401(models::ErrorResponse),
38    Status403(models::ErrorResponse),
39    Status404(models::ErrorResponse),
40    Status503(models::ErrorResponse),
41    Status5XX(models::ErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`list_table_branches`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum ListTableBranchesError {
49    Status400(models::ErrorResponse),
50    Status401(models::ErrorResponse),
51    Status403(models::ErrorResponse),
52    Status404(models::ErrorResponse),
53    Status503(models::ErrorResponse),
54    Status5XX(models::ErrorResponse),
55    UnknownValue(serde_json::Value),
56}
57
58
59/// Create a new branch for table `id` starting from a source ref (another branch and/or version), defaulting to the latest version of the main branch. 
60pub async fn create_table_branch(configuration: &configuration::Configuration, id: &str, create_table_branch_request: models::CreateTableBranchRequest, delimiter: Option<&str>) -> Result<models::CreateTableBranchResponse, Error<CreateTableBranchError>> {
61    // add a prefix to parameters to efficiently prevent name collisions
62    let p_id = id;
63    let p_create_table_branch_request = create_table_branch_request;
64    let p_delimiter = delimiter;
65
66    let uri_str = format!("{}/v1/table/{id}/branches/create", configuration.base_path, id=crate::apis::urlencode(p_id));
67    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
68
69    if let Some(ref param_value) = p_delimiter {
70        req_builder = req_builder.query(&[("delimiter", &param_value.to_string())]);
71    }
72    if let Some(ref user_agent) = configuration.user_agent {
73        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
74    }
75    if let Some(ref token) = configuration.oauth_access_token {
76        req_builder = req_builder.bearer_auth(token.to_owned());
77    };
78    if let Some(ref apikey) = configuration.api_key {
79        let key = apikey.key.clone();
80        let value = match apikey.prefix {
81            Some(ref prefix) => format!("{} {}", prefix, key),
82            None => key,
83        };
84        req_builder = req_builder.header("x-api-key", value);
85    };
86    if let Some(ref token) = configuration.bearer_access_token {
87        req_builder = req_builder.bearer_auth(token.to_owned());
88    };
89    req_builder = req_builder.json(&p_create_table_branch_request);
90
91    let req = req_builder.build()?;
92    let resp = configuration.client.execute(req).await?;
93
94    let status = resp.status();
95    let content_type = resp
96        .headers()
97        .get("content-type")
98        .and_then(|v| v.to_str().ok())
99        .unwrap_or("application/octet-stream");
100    let content_type = super::ContentType::from(content_type);
101
102    if !status.is_client_error() && !status.is_server_error() {
103        let content = resp.text().await?;
104        match content_type {
105            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
106            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTableBranchResponse`"))),
107            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTableBranchResponse`")))),
108        }
109    } else {
110        let content = resp.text().await?;
111        let entity: Option<CreateTableBranchError> = serde_json::from_str(&content).ok();
112        Err(Error::ResponseError(ResponseContent { status, content, entity }))
113    }
114}
115
116/// Delete an existing branch from table `id`. 
117pub async fn delete_table_branch(configuration: &configuration::Configuration, id: &str, delete_table_branch_request: models::DeleteTableBranchRequest, delimiter: Option<&str>) -> Result<models::DeleteTableBranchResponse, Error<DeleteTableBranchError>> {
118    // add a prefix to parameters to efficiently prevent name collisions
119    let p_id = id;
120    let p_delete_table_branch_request = delete_table_branch_request;
121    let p_delimiter = delimiter;
122
123    let uri_str = format!("{}/v1/table/{id}/branches/delete", configuration.base_path, id=crate::apis::urlencode(p_id));
124    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
125
126    if let Some(ref param_value) = p_delimiter {
127        req_builder = req_builder.query(&[("delimiter", &param_value.to_string())]);
128    }
129    if let Some(ref user_agent) = configuration.user_agent {
130        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
131    }
132    if let Some(ref token) = configuration.oauth_access_token {
133        req_builder = req_builder.bearer_auth(token.to_owned());
134    };
135    if let Some(ref apikey) = configuration.api_key {
136        let key = apikey.key.clone();
137        let value = match apikey.prefix {
138            Some(ref prefix) => format!("{} {}", prefix, key),
139            None => key,
140        };
141        req_builder = req_builder.header("x-api-key", value);
142    };
143    if let Some(ref token) = configuration.bearer_access_token {
144        req_builder = req_builder.bearer_auth(token.to_owned());
145    };
146    req_builder = req_builder.json(&p_delete_table_branch_request);
147
148    let req = req_builder.build()?;
149    let resp = configuration.client.execute(req).await?;
150
151    let status = resp.status();
152    let content_type = resp
153        .headers()
154        .get("content-type")
155        .and_then(|v| v.to_str().ok())
156        .unwrap_or("application/octet-stream");
157    let content_type = super::ContentType::from(content_type);
158
159    if !status.is_client_error() && !status.is_server_error() {
160        let content = resp.text().await?;
161        match content_type {
162            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteTableBranchResponse`"))),
164            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteTableBranchResponse`")))),
165        }
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<DeleteTableBranchError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// List all branches that have been created for table `id`. Returns a map of branch names to their contents.  REST NAMESPACE ONLY REST namespace does not use a request body for this operation. The `ListTableBranchesRequest` information is passed in the following way: - `id`: pass through path parameter of the same name - `page_token`: pass through query parameter of the same name - `limit`: pass through query parameter of the same name 
174pub async fn list_table_branches(configuration: &configuration::Configuration, id: &str, delimiter: Option<&str>, page_token: Option<&str>, limit: Option<i32>) -> Result<models::ListTableBranchesResponse, Error<ListTableBranchesError>> {
175    // add a prefix to parameters to efficiently prevent name collisions
176    let p_id = id;
177    let p_delimiter = delimiter;
178    let p_page_token = page_token;
179    let p_limit = limit;
180
181    let uri_str = format!("{}/v1/table/{id}/branches/list", configuration.base_path, id=crate::apis::urlencode(p_id));
182    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
183
184    if let Some(ref param_value) = p_delimiter {
185        req_builder = req_builder.query(&[("delimiter", &param_value.to_string())]);
186    }
187    if let Some(ref param_value) = p_page_token {
188        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
189    }
190    if let Some(ref param_value) = p_limit {
191        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
192    }
193    if let Some(ref user_agent) = configuration.user_agent {
194        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
195    }
196    if let Some(ref token) = configuration.oauth_access_token {
197        req_builder = req_builder.bearer_auth(token.to_owned());
198    };
199    if let Some(ref apikey) = configuration.api_key {
200        let key = apikey.key.clone();
201        let value = match apikey.prefix {
202            Some(ref prefix) => format!("{} {}", prefix, key),
203            None => key,
204        };
205        req_builder = req_builder.header("x-api-key", value);
206    };
207    if let Some(ref token) = configuration.bearer_access_token {
208        req_builder = req_builder.bearer_auth(token.to_owned());
209    };
210
211    let req = req_builder.build()?;
212    let resp = configuration.client.execute(req).await?;
213
214    let status = resp.status();
215    let content_type = resp
216        .headers()
217        .get("content-type")
218        .and_then(|v| v.to_str().ok())
219        .unwrap_or("application/octet-stream");
220    let content_type = super::ContentType::from(content_type);
221
222    if !status.is_client_error() && !status.is_server_error() {
223        let content = resp.text().await?;
224        match content_type {
225            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListTableBranchesResponse`"))),
227            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListTableBranchesResponse`")))),
228        }
229    } else {
230        let content = resp.text().await?;
231        let entity: Option<ListTableBranchesError> = serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent { status, content, entity }))
233    }
234}
235