D
Deno

help

KV list is returning an empty iterator, but data is there and gettable via get

P_Pear9/9/2023
Hello. To simplify things, I am setting a key of ["accounts", account.name] but when I try to get the accounts with kv.list({ prefix: ["accounts"] }), I always get an empty iterator back. I am able to see the record exist when using kv.get(). Here are the relevant snippets; what am I doing wrong, or is this a bug?:
const Db = await Deno.openKv();
//...
await Db.set(["accounts", account.username], account);

//...
const iter = Db.list({ prefix: ["accounts"] }); // why is this always empty?
for await (const row of iter) {
console.log(row);
}
const Db = await Deno.openKv();
//...
await Db.set(["accounts", account.username], account);

//...
const iter = Db.list({ prefix: ["accounts"] }); // why is this always empty?
for await (const row of iter) {
console.log(row);
}
Llcasdev9/9/2023
That doesn't seem right! Can you simplify this into a minimal example that I can try out locally?
P_Pear9/9/2023
sure !one moment Hmmm it seems to work fine in this isolated example:
export const Db = await Deno.openKv("./kv/kv-repro.db");

const makeAccounts = async () => {
const accounts = [
{
username: "test1",
},
{
username: "test2",
},
{
username: "test3",
},
{
username: "test4",
},
];

for (const account of accounts) {
await Db.set(["accounts", account.username], account);
}
};


const listAccounts = async () => {
const iter = Db.list({ prefix: ["accounts"] });
for await (const row of iter) {
console.log(row);
}
};

await makeAccounts();
await listAccounts();
export const Db = await Deno.openKv("./kv/kv-repro.db");

const makeAccounts = async () => {
const accounts = [
{
username: "test1",
},
{
username: "test2",
},
{
username: "test3",
},
{
username: "test4",
},
];

for (const account of accounts) {
await Db.set(["accounts", account.username], account);
}
};


const listAccounts = async () => {
const iter = Db.list({ prefix: ["accounts"] });
for await (const row of iter) {
console.log(row);
}
};

await makeAccounts();
await listAccounts();
Where it's not working for me behind a Hono route so there may be something there I'm missing, I'll report back if I figure it out. Very confused but it seems to be working now w/Hono. Not entirely sure why. Thanks 🙂

Looking for more? Join the community!

Recommended Posts
Read permission & NPM importsHello, I'm using `--allow-read=.` to allow a script to read files in the current directory. The scriWebSocket connections killing setInterval()Hey Deno friends, it appears that websocket connections are somehow stopping the execution of setIntjsx in jsAll of my files containing JSX are in `.js` files. Is there an easy fix for this when running?http errorI need help because I have a service that has more than 1 million requests per day and for about 7 ddoes Deno vscode support nesting `deno.json`?There is a project I'm working on has nesting `deno.json` files. The parent `deno.json` is a bit outDeploy says Worker not defined for ESBuild (wasm.js)@Deno AI Helper I am having trouble understanding how to get the esbuilder to work on Deno Deploy, udeno_tui Label-classHello. I just started testing around with deno_tui and found the DrawObject-Class. How do i actuallyCannot read file "src/deno.json": not implemented on jsHey @Deno AI Helper ! I'm having a bit of trouble, I'm trying to use `deno.land/x/import` to use nonError running Apollo example (on latest version)Hi. When I run this example with the latest version of apollo from npm I get errors: https://deno.Example Question for the Deno AI BotHey there - this is an example question for the Deno AI bot. How would I write a regular expression Does Deno support `export type` statements?Hello, we are using Deno + TS and I am getting the following error if I try to export a type from anHow can one patch a Deno dependency?Hello, We're used to working with node and using `patch-package` to override and fix packages fairly