D
Deno

help

List kv items using a partial key

Ttigawana12/26/2023
Hey guys am trying to figure out kv and how to get stuffout of it how do i get iteme that have the key ["repo_pkgjson",reponame] example
const repos = await kv.get(["repo_pkgjson","tigawanna/all-emps-web"]);
const repos = await kv.get(["repo_pkgjson","tigawanna/all-emps-web"]);
returns
{
"key": [
"repo_pkgjson",
"tigawanna/all-emps-web"
],
"value": {
"name": "all-emps-vite",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "tsc && vite build ",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^4.16.1",
"@tanstack/react-query-devtools": "^4.16.1",
"dayjs": "^1.11.6",
"pocketbase": "^0.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.6.0",
"react-intersection-observer": "^9.4.1",
"react-router-dom": "^6.4.3",
"tailwind-scrollbar": "^2.0.1"
},
"devDependencies": {

},
"pkg_type": "React+Vite",
"favdeps": [
"tailwindcss",
"typescript",
"react-router-dom",
"react-icons",
"dayjs",
"pocketbase"
]
},
"versionstamp": "000000000000046d0000"
}
{
"key": [
"repo_pkgjson",
"tigawanna/all-emps-web"
],
"value": {
"name": "all-emps-vite",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "tsc && vite build ",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^4.16.1",
"@tanstack/react-query-devtools": "^4.16.1",
"dayjs": "^1.11.6",
"pocketbase": "^0.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.6.0",
"react-intersection-observer": "^9.4.1",
"react-router-dom": "^6.4.3",
"tailwind-scrollbar": "^2.0.1"
},
"devDependencies": {

},
"pkg_type": "React+Vite",
"favdeps": [
"tailwindcss",
"typescript",
"react-router-dom",
"react-icons",
"dayjs",
"pocketbase"
]
},
"versionstamp": "000000000000046d0000"
}
but this
const repos = await kv.list({prefix: ["repo_pkgjson"]});
const repos = await kv.list({prefix: ["repo_pkgjson"]});
returns an empty array , waht am i doing wrong?
Ccknight12/26/2023
Can you show the full code? kv.list returns an async iterator, not an array of entries. You want to do for await (const repo of repos) { ... } with the result of the list operation.
ABAltair 680b12/26/2023
list returns a KvListIterator. You must await each entry.
const entries = db.list({ prefix: ["repo_pkgjson"] })
for await (const entry of entries) {
console.info('key: ', entry.key)
console.info('value ', entry.value)
}
const entries = db.list({ prefix: ["repo_pkgjson"] })
for await (const entry of entries) {
console.info('key: ', entry.key)
console.info('value ', entry.value)
}
https://deno.land/api@v1.35.3?unstable=&s=Deno.Kv&p=prototype.list
Ttigawana12/27/2023
Thanks guys it worked
Eeric.uhd12/27/2023
Better yet since Deno 1.38: - in one step
const repos = await Array.fromAsync(kv.list({ prefix: ["repo_pkgjson"] }));
const repos = await Array.fromAsync(kv.list({ prefix: ["repo_pkgjson"] }));
- in two steps
const iter = kv.list({ prefix: ["repo_pkgjson"] });
const repos = await Array.fromAsync(iter);
const iter = kv.list({ prefix: ["repo_pkgjson"] });
const repos = await Array.fromAsync(iter);
And you can still access each of them before storing them. For instance if you just want the Value and not the KV Part Key nor the Versionstamp:
const iter = kv.list({ prefix: ["repo_pkgjson"] });
const repos = await Array.fromAsync(iter, repo => repo.value);
const iter = kv.list({ prefix: ["repo_pkgjson"] });
const repos = await Array.fromAsync(iter, repo => repo.value);
Ttigawana12/27/2023
Thank you even more

Looking for more? Join the community!

Recommended Posts
Is there a recommended library to do dependency injection in Deno?I'm creating a Rest API with the repository and controllers pattern but my code in the `main.ts` filReact (CRA) deploy via denoGetting an error while building react CRA via deno deploy. Error: ENOENT: no such file or directoryCustom executable icon for `deno compile`?Is it possible to set a different icon rather than the default deno icon for the executable generateDeno.Command output as it runsHello, I am trying to run a command and have its output be logged as it runs , but for some reason telectrons using denoIn the recent deno version I see it is possible to runn executable in ./bin in node_modules using Cannot find moduleHi <:vmathi:812484657547313212> I'm trying to run a project with Deno, but i'm getting "Cannot find Uncaught error during deno deploy of vite appWhen creating a new vite app with vue and typescript I get this error message. This error is reprodDeno, TypeScript, ESBuild, WebGL, VSCodeHello! As the title suggests, I am using these technologies to create a web application: * Deno * TPossible issue with re-export compatibility with NodeIn https://github.com/japa/runner/issues/35, I have described an issue where Deno seems to be incompMake deno.serve handler asynchronousHow can i make the Deno.serve handler asynchronous? or like make it so that it can execute asynchronWhy my place.x -= 5 not working?At this part if(moveKey.right.pressed) { finishPostion += 5 quota exceededi hit the free limit tonight and upgraded to pro 20 minutes ago— when do my sites stop erroring with