sangrepura
sangrepura
CDCloudflare Developers
Created by sangrepura on 1/28/2024 in #general-help
Help needed: How do i seed my local KV store?
I could find no documentation on this (wtf Cloudfare) The official docs on KV (https://developers.cloudflare.com/kv/get-started/) were no help:
5. Develop locally with Wrangler
When using wrangler dev to develop locally, wrangler will default to using a local version of KV to avoid interfering with any of your live production data in KV. This means that reading keys that you have not written locally will return null.

To have wrangler dev connect to your Workers KV namespace running on Cloudflare’s global network, call wrangler dev --remote instead.

While in your project directory, test your KV locally by running:

wrangler dev

When you run wrangler dev, Wrangler will give you a URL (usually a localhost:8787) to review your Worker. After you visit the URL Wrangler provides, you will see your value printed on the browser.
5. Develop locally with Wrangler
When using wrangler dev to develop locally, wrangler will default to using a local version of KV to avoid interfering with any of your live production data in KV. This means that reading keys that you have not written locally will return null.

To have wrangler dev connect to your Workers KV namespace running on Cloudflare’s global network, call wrangler dev --remote instead.

While in your project directory, test your KV locally by running:

wrangler dev

When you run wrangler dev, Wrangler will give you a URL (usually a localhost:8787) to review your Worker. After you visit the URL Wrangler provides, you will see your value printed on the browser.
But this is wrong:
wrangler pages dev ./public --kv=testNS --remote

X [ERROR] Unknown argument: remote
wrangler pages dev [directory] [-- command..]
wrangler pages dev ./public --kv=testNS --remote

X [ERROR] Unknown argument: remote
wrangler pages dev [directory] [-- command..]
This post: https://discord.com/channels/595317990191398933/779390076219686943/1151865479556767804 suggested that --persist-to=.wrangler/state would replicate what's in production locally but that's not the case. Also I tried running:
wrangler --binding=testNS kv:key put 'product-11' '{"name": "product 11"}' --local
wrangler --binding=testNS kv:key put 'product-11' '{"name": "product 11"}' --local
an this creatd a new sqlite db and added an entry and added an entry to 177ed01a21109c36f2c8627b05dd953e17084c7d07502c2ba22320 5c6b30c8c4.sqlite that looks like this:
{
"key": "product-11",
"blob_id": "00f0f29d674f8dcf9b11c29e1347dd907ab374a7f66badd128afd4e9324506b30000018d51bb954c",
"expiration": null,
"metadata": null
}
{
"key": "product-11",
"blob_id": "00f0f29d674f8dcf9b11c29e1347dd907ab374a7f66badd128afd4e9324506b30000018d51bb954c",
"expiration": null,
"metadata": null
}
And of course my loader function is not reading this at all.
My app works in production just fine. This is Remix app by the way How do I seed my KV DB? Any help would be appreciated!
11 replies