Skip to content

Commit

Permalink
refactor: simplify db:dump task (denoland#511)
Browse files Browse the repository at this point in the history
Related to denoland#471
  • Loading branch information
iuioiua authored Sep 5, 2023
1 parent b471ec7 commit 03f5d8e
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions tasks/db_dump.ts
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();

0 comments on commit 03f5d8e

Please sign in to comment.