-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Workers KV bulk upload API endpoint #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other places ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may want to join the discussion here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chatted with the KV team and apparently they use i64! I will use that instead (its max value is much larger than u32). |
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub base64: Option<bool>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be leveraging mechanisms discussed in dtolnay/request-for-implementation#18 for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is borat voice VERY NaIIICE (I added it in https://github.com/cloudflare/cloudflare-rs/pull/31/files) |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this hold?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It holds an expiration date (seconds since epoch)