use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct D1GetDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1GetDatabaseDatabaseId, String>,
}
impl<'a> D1GetDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1GetDatabaseDatabaseId>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1GetDatabaseDatabaseId` for database_id failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_get_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1UpdateDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
body: Result<types::builder::D1DatabaseUpdateRequestBody, String>,
}
impl<'a> D1UpdateDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseUpdateRequestBody>,
<V as std::convert::TryInto<types::D1DatabaseUpdateRequestBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `D1DatabaseUpdateRequestBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::D1DatabaseUpdateRequestBody,
) -> types::builder::D1DatabaseUpdateRequestBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::D1DatabaseUpdateRequestBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_update_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1DeleteDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
}
impl<'a> D1DeleteDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.delete(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_delete_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1UpdatePartialDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
body: Result<types::builder::D1DatabaseUpdatePartialRequestBody, String>,
}
impl<'a> D1UpdatePartialDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseUpdatePartialRequestBody>,
<V as std::convert::TryInto<types::D1DatabaseUpdatePartialRequestBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `D1DatabaseUpdatePartialRequestBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::D1DatabaseUpdatePartialRequestBody,
) -> types::builder::D1DatabaseUpdatePartialRequestBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::D1DatabaseUpdatePartialRequestBody::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.patch(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_update_partial_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1ExportDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
body: Result<types::builder::D1ExportDatabaseBody, String>,
}
impl<'a> D1ExportDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1ExportDatabaseBody>,
<V as std::convert::TryInto<types::D1ExportDatabaseBody>>::Error: std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `D1ExportDatabaseBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::D1ExportDatabaseBody,
) -> types::builder::D1ExportDatabaseBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| types::D1ExportDatabaseBody::try_from(v).map_err(|e| e.to_string()))
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}/export",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_export_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1ImportDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
body: Result<types::D1ImportDatabaseBody, String>,
}
impl<'a> D1ImportDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1ImportDatabaseBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `D1ImportDatabaseBody` for body failed".to_string());
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}/import",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_import_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1QueryDatabase<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
body: Result<types::D1BatchQuery, String>,
}
impl<'a> D1QueryDatabase<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1BatchQuery>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `D1BatchQuery` for body failed".to_string());
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}/query",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_query_database",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1RawDatabaseQuery<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
body: Result<types::D1BatchQuery, String>,
}
impl<'a> D1RawDatabaseQuery<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1BatchQuery>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `D1BatchQuery` for body failed".to_string());
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}/raw",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_raw_database_query",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1TimeTravelGetBookmark<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
timestamp: Result<types::D1TimeTravelTimestamp, String>,
}
impl<'a> D1TimeTravelGetBookmark<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
timestamp: Err("timestamp was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn timestamp<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1TimeTravelTimestamp>,
{
self.timestamp = value.try_into().map_err(|_| {
"conversion to `D1TimeTravelTimestamp` for timestamp failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
timestamp,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let timestamp = timestamp.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}/time_travel/bookmark",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.query(&progenitor_client::QueryParam::new("timestamp", ×tamp))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_time_travel_get_bookmark",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct D1TimeTravelRestore<'a> {
client: &'a crate::Client,
account_id: Result<types::D1AccountIdentifier, String>,
database_id: Result<types::D1DatabaseIdentifier, String>,
bookmark: Result<types::D1TimeTravelBookmark, String>,
timestamp: Result<types::D1TimeTravelTimestamp, String>,
}
impl<'a> D1TimeTravelRestore<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
database_id: Err("database_id was not initialized".to_string()),
bookmark: Err("bookmark was not initialized".to_string()),
timestamp: Err("timestamp was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1AccountIdentifier>,
{
self.account_id = value.try_into().map_err(|_| {
"conversion to `D1AccountIdentifier` for account_id failed".to_string()
});
self
}
pub fn database_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1DatabaseIdentifier>,
{
self.database_id = value.try_into().map_err(|_| {
"conversion to `D1DatabaseIdentifier` for database_id failed".to_string()
});
self
}
pub fn bookmark<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1TimeTravelBookmark>,
{
self.bookmark = value.try_into().map_err(|_| {
"conversion to `D1TimeTravelBookmark` for bookmark failed".to_string()
});
self
}
pub fn timestamp<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::D1TimeTravelTimestamp>,
{
self.timestamp = value.try_into().map_err(|_| {
"conversion to `D1TimeTravelTimestamp` for timestamp failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
database_id,
bookmark,
timestamp,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let database_id = database_id.map_err(Error::InvalidRequest)?;
let bookmark = bookmark.map_err(Error::InvalidRequest)?;
let timestamp = timestamp.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/d1/database/{}/time_travel/restore",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&database_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.query(&progenitor_client::QueryParam::new("bookmark", &bookmark))
.query(&progenitor_client::QueryParam::new("timestamp", ×tamp))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "d1_time_travel_restore",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}