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

chore: set KV_PATH environment variable #285

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"db:seed": "deno run --allow-read --allow-env --allow-net --unstable tools/seed_submissions.ts",
"db:reset": "deno run --allow-read --allow-env --unstable tools/reset_kv.ts",
"start": "deno run --unstable -A --watch=static/,routes/ dev.ts",
"test": "deno test -A --unstable --coverage=./cov",
"test": "KV_PATH=:memory: deno test -A --unstable --coverage=./cov",
"check:license": "deno run --allow-read --allow-write tools/check_license.ts",
"ok": "deno fmt --check && deno lint && deno task check:license --check && deno check main.ts && deno task test",
"cov": "deno coverage ./cov/ --lcov --exclude='test.ts' > cov.lcov"
Expand Down
10 changes: 9 additions & 1 deletion utils/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import { DAY, WEEK } from "std/datetime/constants.ts";

export const kv = await Deno.openKv();
const KV_PATH_KEY = "KV_PATH";
let path = undefined;
if (
(await Deno.permissions.query({ name: "env", variable: KV_PATH_KEY }))
.state === "granted"
) {
path = Deno.env.get(KV_PATH_KEY);
}
export const kv = await Deno.openKv(path);

// Helpers
async function getValue<T>(
Expand Down