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!
Get started · Cloudflare Workers KV
Workers KV provides low-latency, high-throughput global storage to your Cloudflare Workers applications. Workers KV is ideal for storing user …
6 Replies
Chaika
Chaika10mo ago
This would be better fit in #pages-help
wrangler dev
wrangler dev is for Workers and supports --remote
wrangler pages dev
is for Pages and only supports local mode (I sent my msg on accident lol, I'll add more below, one sec)
suggested that --persist-to=.wrangler/state would replicate what's in production locally but that's not the case.
Persist to just specifies the directory to save local data at. It won't pull anything down. He just wanted multiple local workers to share the same data
sangrepura
sangrepuraOP10mo ago
OK thank you! I did run pages dev --local and tried adding an entry using
wrangler --binding=test
NS kv:key put 'product-13' '{"name":"product 13"}' --local -
-preview false
⛅️ wrangler 3.25.0
-------------------
Writing the value "{"name":"product 13"}" to key "product-13
" on namespace 10cae290a79b4a49a9f5d4f8d1c51539.
wrangler --binding=test
NS kv:key put 'product-13' '{"name":"product 13"}' --local -
-preview false
⛅️ wrangler 3.25.0
-------------------
Writing the value "{"name":"product 13"}" to key "product-13
" on namespace 10cae290a79b4a49a9f5d4f8d1c51539.
but it just adds a blob entry to _mf_entries and my app cannot read it. This has been a terrible DX so far Oh and I'm running my app like so:
wrangler pages dev ./public --kv=testNS --local --live-reload
wrangler pages dev ./public --kv=testNS --local --live-reload
Chaika
Chaika10mo ago
They're working on convergence, making Pages/Workers into one product, but that's far into the future. Right now it is def a bit confusing, running pages dev --local shouldn't do anything. Pages dev only supports local mode. The preview kv would only be used for running workers with --remote, i.e there's --local (default and only option for Pages), which uses Miniflare/workerd simulated resources --remote which uses preview IDs and such actual production deployment which uses the real IDs
sangrepura
sangrepuraOP10mo ago
They sure don't present it this way. This blog post from 21/12 presents it as ready for prime time https://blog.cloudflare.com/remix-on-cloudflare-pages I really don't want to have to deploy just to test my app, and adding a k/v entry with wrangler locally should not be creating blobs my app can't read. It's supposed to be JSON data. Am I missing something/ doing it wrong?
The Cloudflare Blog
Supporting Remix with full stack Cloudflare Pages
Cloudflare Pages now natively supports full stack Remix applications.
Chaika
Chaika10mo ago
Doesn't mean it's not ready, just saying local dev and the difference docs/etc is a bit rough with Pages do you have a wrangler.toml created in your project? I believe to write to the same one as it uses, you'd want
wrangler --namespace-id=testNS kv:key put 'product-13' '{"name":"product 13"}' --local
wrangler --namespace-id=testNS kv:key put 'product-13' '{"name":"product 13"}' --local
the namespace-id is what pages-dev uses, you can see in your original command it was storing it under the actual live id
sangrepura
sangrepuraOP10mo ago
Wow, ok that actually worked. THANK YOU! I now have 3 sqllite dbs in my state dir but I'm able to use it in my route's loader function
Want results from more Discord servers?
Add your server