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: cleanup
db:reset
script (denoland#509)
This cleans up some of the unnecessary LOC for the script. Related to denoland#471
- Loading branch information
Showing
1 changed file
with
7 additions
and
17 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,21 +1,11 @@ | ||
// Copyright 2023 the Deno authors. All rights reserved. MIT license. | ||
import { kv } from "@/utils/db.ts"; | ||
|
||
export async function resetKv() { | ||
const iter = kv.list({ prefix: [] }); | ||
const promises = []; | ||
for await (const res of iter) promises.push(kv.delete(res.key)); | ||
await Promise.all(promises); | ||
} | ||
if (!confirm("WARNING: The database will be reset. Continue?")) Deno.exit(); | ||
|
||
if (import.meta.main) { | ||
if ( | ||
!confirm( | ||
"This script deletes all data from the Deno KV database. Are you sure you'd like to continue?", | ||
) | ||
) { | ||
close(); | ||
} | ||
await resetKv(); | ||
await kv.close(); | ||
} | ||
const iter = kv.list({ prefix: [] }); | ||
const promises = []; | ||
for await (const res of iter) promises.push(kv.delete(res.key)); | ||
await Promise.all(promises); | ||
|
||
kv.close(); |