From 3b1fc75eee054b65baae3b08f084f88c7592cae9 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 22 Jun 2023 19:51:12 +1000 Subject: [PATCH] chore: set `KV_PATH` env var --- deno.json | 2 +- utils/db.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/deno.json b/deno.json index 004c2cd66..2b88a6e37 100644 --- a/deno.json +++ b/deno.json @@ -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" diff --git a/utils/db.ts b/utils/db.ts index 899b3889e..b1dd69e32 100644 --- a/utils/db.ts +++ b/utils/db.ts @@ -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(