Damien
Damienβ€’2w ago

How do I get all entries out of Deno.kv

Apologies if this is covered somewhere, I have tried searching through the history. I have the following data (see pic) I want to get all "subscribers" so that I can list them out but I seem to be coming up short with what I am trying which is below
const kv = await Deno.openKv();
const subscribers: Subscriber[] = [];

const entries = kv.list<{ email: string; timestamp: string }>({
prefix: ["subscribers"],
});

for await (const entry of entries) {
console.log("Entry:", entry); // Debug log
if (entry.value) {
subscribers.push({
email: entry.value.email,
timestamp: entry.value.timestamp,
});
}
}
kv.close();
const kv = await Deno.openKv();
const subscribers: Subscriber[] = [];

const entries = kv.list<{ email: string; timestamp: string }>({
prefix: ["subscribers"],
});

for await (const entry of entries) {
console.log("Entry:", entry); // Debug log
if (entry.value) {
subscribers.push({
email: entry.value.email,
timestamp: entry.value.timestamp,
});
}
}
kv.close();
The only thing I can think of is that my keys are actually ["subscribers","uuid" but I do not know how to get around that! Thanks in advance for any guidance / pointers on the above! Really enjoying using Deno + Fresh!
No description
7 Replies
Damien
Damienβ€’2w ago
Hmm so deploying it, it seems to work but when running locally, I get no data. Is that to be expected?
wesbos
wesbosβ€’2w ago
silly Q: do you have local KV data? You can connect to the remote KV DB if needed
Damien
Damienβ€’2w ago
Hey Wes! Not a silly question as I am most definitely not using any local KV data, I didn't even realise that was a thing (naively) - I've been using Turso lately and my brain was just used to having it connected without thinking about it πŸ˜… Connecting to the remove URL would be good! I assume there is some docs for that for me to look at? I've found an example of conntecting to remote data when opening the KV store. I guess my only question is, is it fine to leave it in there or will it break something with the connection when deployed?
wesbos
wesbosβ€’2w ago
Nope it’s fine just make sure you know you are dealing with production data locally
Damien
Damienβ€’2w ago
Awesome cheers!
wesbos
wesbosβ€’2w ago
np! I'm using KV for this site to log number of times people use fav icons, and I have to connect to the remote KV every now and then because people are running up the numbers 🀣 https://fav.farm/
Damien
Damienβ€’2w ago
I am always in need of a random favicon πŸ˜‚ love this! I did in fact, run into a few problems Wes πŸ˜… Managed to set the DENO_KV_ACCESS_TOKEN which made everything work locally but when I deployed it, it fell over. I could not add the same token to the project as DENO_ is a reserved key word.