8 releases (breaking)

0.7.0 Apr 6, 2024
0.6.0 Mar 8, 2023
0.5.1 Dec 22, 2021
0.4.0 Oct 1, 2021
0.1.1 Mar 23, 2021

#33 in #cloudflare-workers

Download history 10606/week @ 2024-03-14 5218/week @ 2024-03-21 21503/week @ 2024-03-28 5920/week @ 2024-04-04 6639/week @ 2024-04-11 6513/week @ 2024-04-18 6914/week @ 2024-04-25 6086/week @ 2024-05-02 4600/week @ 2024-05-09 13199/week @ 2024-05-16 12636/week @ 2024-05-23 7743/week @ 2024-05-30 12698/week @ 2024-06-06 8570/week @ 2024-06-13 9042/week @ 2024-06-20 10077/week @ 2024-06-27

42,246 downloads per month
Used in 26 crates (4 directly)

MIT/Apache

22KB
389 lines

worker-kv

Docs.rs Crates.io MIT Apache 2

Rust bindings to Cloudflare Worker KV Stores using wasm-bindgen and js-sys.

Example

let kv = KvStore::create("Example")?; // or KvStore::from_this(&this, "Example") if using modules format Workers

// Insert a new entry into the kv.
kv.put("example_key", "example_value")?
    .metadata(vec![1, 2, 3, 4]) // Use some arbitrary serialiazable metadata
    .execute()
    .await?;

// NOTE: kv changes can take a minute to become visible to other workers.
// Get that same metadata.
let (value, metadata) = kv.get("example_key").text_with_metadata::<Vec<usize>>().await?;

For a more complete example check out the full example.

How do I use futures in WebAssembly?

There currently is not a way to use a Future natively from WebAssembly but with the future_to_promise function from wasm_bindgen_futures we can convert it to a standard JavaScript promise, which can be awaited in the regular JavaScript context.

Dependencies

~1.3–3.5MB
~67K SLoC