diff --git a/docs/content/kv_commands.md b/docs/content/kv_commands.md index a53868d48..af692dc46 100644 --- a/docs/content/kv_commands.md +++ b/docs/content/kv_commands.md @@ -25,7 +25,7 @@ $ wrangler kv:namespace create "MY_KV" } ✨ Add the following to your wrangler.toml: kv-namespaces = [ - { binding: "MY_KV", id: "e29b263ab50e42ce9b637fa8370175e8" } + { binding = "MY_KV", id = "e29b263ab50e42ce9b637fa8370175e8" } ] ``` Make sure to add the `kv-namespaces` output above to your `wrangler.toml`. You can now @@ -53,12 +53,12 @@ one for staging and one for production). So, if you have a `wrangler.toml` with ```toml [env.staging] kv-namespaces = [ - { binding: "MY_KV", id: "e29b263ab50e42ce9b637fa8370175e8" } + { binding = "MY_KV", id = "e29b263ab50e42ce9b637fa8370175e8" } ] [env.production] kv-namespaces = [ - { binding: "MY_KV", id: "a825455ce00f4f7282403da85269f8ea" } + { binding = "MY_KV", id = "a825455ce00f4f7282403da85269f8ea" } ] ``` @@ -134,7 +134,7 @@ $ wrangler kv:namespace create "MY_KV" } ✨ Add the following to your wrangler.toml: kv-namespaces = [ - { binding: "MY_KV", id: "e29b263ab50e42ce9b637fa8370175e8" } + { binding = "MY_KV", id = "e29b263ab50e42ce9b637fa8370175e8" } ] ``` @@ -309,12 +309,15 @@ $ wrangler kv:bulk put --binding=KV allthethingsupload.json Requires `--binding` or `--namespace-id` argument. Deletes all specified keys within a given namespace. -Takes as an argument a JSON file with a list of keys to delete; for example: +Takes as an argument a JSON file with a list of key-value pairs to delete (see JSON spec above). An example of JSON input: ```json [ - "key1", - "key2" + { + "key": "test_key", + "value": "test_value", + "expiration_ttl": 3600 + } ] ``` diff --git a/src/commands/kv/bulk/delete.rs b/src/commands/kv/bulk/delete.rs index 150440f0a..428d80fe5 100644 --- a/src/commands/kv/bulk/delete.rs +++ b/src/commands/kv/bulk/delete.rs @@ -5,6 +5,7 @@ use std::fs::metadata; use std::path::Path; use cloudflare::endpoints::workerskv::delete_bulk::DeleteBulk; +use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair; use cloudflare::framework::apiclient::ApiClient; use crate::commands::kv; @@ -31,12 +32,12 @@ pub fn delete( Err(e) => failure::bail!(e), } - let keys: Result, failure::Error> = match &metadata(filename) { + let pairs: Result, failure::Error> = match &metadata(filename) { Ok(file_type) if file_type.is_file() => { let data = fs::read_to_string(filename)?; let keys_vec = serde_json::from_str(&data); if keys_vec.is_err() { - failure::bail!("Failed to decode JSON. Please make sure to follow the format, [\"test_key_1\", \"test_key_2\", ...]") + failure::bail!("Failed to decode JSON. Please make sure to follow the format, [{\"key\": \"test_key\", \"value\": \"test_value\"}, ...]") } else { Ok(keys_vec.unwrap()) } @@ -45,7 +46,9 @@ pub fn delete( Err(e) => failure::bail!("{}", e), }; - delete_bulk(target, user, namespace_id, keys?) + let keys: Vec = pairs?.iter().map(|kv| kv.key.to_owned()).collect(); + + delete_bulk(target, user, namespace_id, keys) } fn delete_bulk( diff --git a/src/commands/kv/namespace/create.rs b/src/commands/kv/namespace/create.rs index def343ad8..55dae318e 100644 --- a/src/commands/kv/namespace/create.rs +++ b/src/commands/kv/namespace/create.rs @@ -48,7 +48,7 @@ pub fn create( }; println!( "kv-namespaces = [ \n\ - \t {{ binding: \"{}\", id: \"{}\" }} \n\ + \t {{ binding = \"{}\", id = \"{}\" }} \n\ ]", binding, success.result.id );