-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from gabbifish/add-workers-kv-bulk-upload
Add support for Workers KV bulk upload API endpoint
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::framework::endpoint::{Endpoint, Method}; | ||
|
||
/// Write Key-Value Pairs in Bulk | ||
/// Writes multiple key-value pairs to Workers KV at once. | ||
/// A 404 is returned if a write action is for a namespace ID the account doesn't have. | ||
/// https://api.cloudflare.com/#workers-kv-namespace-write-multiple-key-value-pairs | ||
pub struct WriteBulk<'a> { | ||
pub account_identifier: &'a str, | ||
pub namespace_identifier: &'a str, | ||
pub bulk_key_value_pairs: Vec<KeyValuePair>, | ||
} | ||
|
||
impl<'a> Endpoint<(), (), Vec<KeyValuePair>> for WriteBulk<'a> { | ||
fn method(&self) -> Method { | ||
Method::Put | ||
} | ||
fn path(&self) -> String { | ||
format!( | ||
"accounts/{}/storage/kv/namespaces/{}/bulk", | ||
self.account_identifier, self.namespace_identifier | ||
) | ||
} | ||
fn body(&self) -> Option<Vec<KeyValuePair>> { | ||
Some(self.bulk_key_value_pairs.clone()) | ||
} | ||
// default content-type is already application/json | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct KeyValuePair { | ||
pub key: String, | ||
pub value: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub expiration: Option<i32>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub expiration_ttl: Option<i32>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub base64: Option<bool>, | ||
} |