Skip to content

Commit 03f5d8e

Browse files
authored
refactor: simplify db:dump task (denoland#511)
Related to denoland#471
1 parent b471ec7 commit 03f5d8e

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

tasks/db_dump.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
2-
// Description: Prints kv to stdout
3-
// Usage: deno run -A --unstable tools/dump_kv.ts
42
import { kv } from "@/utils/db.ts";
53

64
// https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-521460510
75
function replacer(_key: unknown, value: unknown) {
8-
return typeof value === "bigint" ? value.toString() : value; // return everything else unchanged
9-
}
10-
export async function dumpKv() {
11-
const iter = kv.list({ prefix: [] });
12-
const items = [];
13-
for await (const res of iter) {
14-
items.push({ [res.key.toString()]: res.value });
15-
}
16-
console.log(`${JSON.stringify(items, replacer, 2)}`);
6+
return typeof value === "bigint" ? value.toString() : value;
177
}
188

19-
if (import.meta.main) {
20-
await dumpKv();
21-
await kv.close();
22-
}
9+
const iter = kv.list({ prefix: [] });
10+
const items = [];
11+
for await (const res of iter) items.push({ [res.key.toString()]: res.value });
12+
console.log(`${JSON.stringify(items, replacer, 2)}`);
13+
14+
kv.close();

0 commit comments

Comments
 (0)