Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify db:dump task #511

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();