Skip to content
Commit Detail

Commit 123c205

Author
Kenton Varda <kenton@cloudflare.com> 2025-08-25 18:29:42 -0500
Parents
8ab815e
Tree
1b5963a
Implement synchronous version of DO KV storage API.

This adds `ctx.storage.kv`, which has methods `get()`, `put()`, `list()`, and `delete()`. All four methods have the same signatures as the same-named methods of `ctx.storage` except:
1. They return synchronously. No promises.
2. They require SQLite-backed DOs.
3. They don't have the `allowConcurrency` nor `noCache` options since those don't make sense for SQLite. (Nothing stops you from passing these options anyway; they will be ignored.)
4. The `allowUnconfirmed` option is also absent, not because it doesn't make sense, but becaues we haven't actually implemented it for SQLite-backed DOs in general. Maybe we will eventually.
5. Obscure: If you `get()` multiple keys at once, the returned map now iterates in the order in which the keys were specified, rather than in alphabetical order. The old interface's alphabetical ordering was a historical quirk that required an extra sort operation. It had been maintained for backwards-compatibility, but probably nobody really cares about it, so the new interface takes the opportunity to skip the sort.

The name `storage.kv` nicely parallels `storage.sql` while avoiding any backwards-compatibility concerns. In the long term we should "deprecate" (but forever support) the old async methods.

Files changed