Óscar
Óscar14mo ago

What is the best way to count values with Deno.Kv?

I want to show the total values in the database. It seems that the only way is with kv.list() and then iterate the values. Probably this is not very performant if I only want to count the results. I'd like to have something like this:
const count = await kv.count(["users"]);

console.log(`There are ${count} users in the database`);
const count = await kv.count(["users"]);

console.log(`There are ${count} users in the database`);
2 Replies
iuioiua
iuioiua14mo ago
GitHub
suggestion: Deno.Kv.count() · Issue #18965 · denoland/deno
This would be useful for cases where one would like to know how many entries exist for a given prefix without processing/storing any of the actual data. Example: const count = await kv.count({ pref...
Óscar
Óscar14mo ago
Oh, I didn't see that. Thanks!