Export your Cloudflare Workers KV namespaces to sqlite for querying
Helpful if you need to explore your KV data with SQL, such as joining, extracting JSON values etc.
npm install
Usage: node export <config.toml> <apiKey>
Sample config.toml
account_id = "xxx"
auth_email = "[email protected]"
filename = "kv.db"
# You can suppress values being written, such as if values are large
kv-namespaces = [
{ title = "NAMESPACE_1", id = "yyy" },
{ title = "BIG_NAMESPACE_2", id = "zzz", values = "false" },
]
Once you've exported your data, you can query in sqlite using the json
function.
For example:
SELECT DISTINCT json_extract(json(val), '$.subscriptions[0].bookId') as bookId
FROM ACCOUNTS
where bookId is not NULL
- Creates a table in a local sqlite db for each KV Namespace you specify in the toml
- Paginates keys for namespaces with > 1000 keys
- Upserts to support re-runs
- Can get or supress retrieving the values