Cloudflare KV namespace and value lifecycle
Lists the keys in a KV namespace, and covers the whole lifecycle around it: creating a namespace, writing a value, reading it back, and deleting both. Namespaces are managed through the Cloudflare API like any other resource, while values are raw bytes written to the same surface - so a single query language spans the control plane and the data plane without changing tools.
Query
SELECT name
FROM cloudflare.kv.keys
WHERE account_id = '{{account_id}}'
AND namespace_id = '{{namespace_id}}';
Listing and creating namespaces
SELECT id, title
FROM cloudflare.kv.namespaces
WHERE account_id = '{{account_id}}';
INSERT INTO cloudflare.kv.namespaces (title, account_id)
SELECT 'my-namespace', '{{account_id}}'
RETURNING result;
Writing and reading a value
The write is a REPLACE and data__value carries the raw request body:
REPLACE cloudflare.kv.values
SET data__value = 'hello from stackql'
WHERE account_id = '{{account_id}}'
AND namespace_id = '{{namespace_id}}'
AND key_name = 'my-key';
SELECT contents
FROM cloudflare.kv.values
WHERE account_id = '{{account_id}}'
AND namespace_id = '{{namespace_id}}'
AND key_name = 'my-key';
Deleting a value and a namespace
DELETE FROM cloudflare.kv.values
WHERE account_id = '{{account_id}}'
AND namespace_id = '{{namespace_id}}'
AND key_name = 'my-key';
DELETE FROM cloudflare.kv.namespaces
WHERE namespace_id = '{{namespace_id}}'
AND account_id = '{{account_id}}';
Notes
data__value is mandatory on the value write and is deliberately not the same convention as the rest of the provider: the naive request-body transform is disabled for this method so that data__value can be splatted verbatim as an application/octet-stream body, which is what lets a value hold arbitrary bytes rather than JSON. The namespace create returns the new namespace inside a result document, so RETURNING result then reading the id out of it is the way to capture the id in one step - otherwise list namespaces and match on title. Reading a key that does not exist returns HTTP 404 with code 10009 'key not found' rather than an empty result, so treat that error as the absence of a key rather than a failure. Deleting a namespace destroys every key in it and cannot be undone, so always scope the delete by namespace_id. The API token needs Account -> Workers KV Storage -> Edit for the writes.