forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify
db:dump
task (denoland#511)
Related to denoland#471
- Loading branch information
Showing
1 changed file
with
7 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
// Copyright 2023 the Deno authors. All rights reserved. MIT license. | ||
// Description: Prints kv to stdout | ||
// Usage: deno run -A --unstable tools/dump_kv.ts | ||
import { kv } from "@/utils/db.ts"; | ||
|
||
// https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-521460510 | ||
function replacer(_key: unknown, value: unknown) { | ||
return typeof value === "bigint" ? value.toString() : value; // return everything else unchanged | ||
} | ||
export async function dumpKv() { | ||
const iter = kv.list({ prefix: [] }); | ||
const items = []; | ||
for await (const res of iter) { | ||
items.push({ [res.key.toString()]: res.value }); | ||
} | ||
console.log(`${JSON.stringify(items, replacer, 2)}`); | ||
return typeof value === "bigint" ? value.toString() : value; | ||
} | ||
|
||
if (import.meta.main) { | ||
await dumpKv(); | ||
await kv.close(); | ||
} | ||
const iter = kv.list({ prefix: [] }); | ||
const items = []; | ||
for await (const res of iter) items.push({ [res.key.toString()]: res.value }); | ||
console.log(`${JSON.stringify(items, replacer, 2)}`); | ||
|
||
kv.close(); |