Let DB_PATH be configurable

This commit is contained in:
Alex Gleason 2023-08-10 13:37:56 -05:00
parent 8ebd85b760
commit 14eb3cb43b
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 6 additions and 2 deletions

View File

@ -5,7 +5,7 @@
"start": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable src/server.ts", "start": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable src/server.ts",
"dev": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable --watch src/server.ts", "dev": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable --watch src/server.ts",
"debug": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable --inspect src/server.ts", "debug": "deno run --allow-read --allow-write=data --allow-env --allow-net --unstable --inspect src/server.ts",
"test": "deno test --allow-read --allow-write=data --allow-env --unstable src", "test": "DB_PATH=\":memory:\" deno test --allow-read --allow-write=data --allow-env --unstable src",
"check": "deno check --unstable src/server.ts" "check": "deno check --unstable src/server.ts"
}, },
"imports": { "imports": {

View File

@ -45,6 +45,9 @@ const Conf = {
get localDomain() { get localDomain() {
return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000'; return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000';
}, },
get dbPath() {
return Deno.env.get('DB_PATH') || 'data/db.sqlite3';
},
get postCharLimit() { get postCharLimit() {
return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000); return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000);
}, },

View File

@ -2,6 +2,7 @@ import fs from 'node:fs/promises';
import path from 'node:path'; import path from 'node:path';
import { DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator, Sqlite } from '@/deps.ts'; import { DenoSqliteDialect, FileMigrationProvider, Kysely, Migrator, Sqlite } from '@/deps.ts';
import { Conf } from '@/config.ts';
interface DittoDB { interface DittoDB {
events: EventRow; events: EventRow;
@ -35,7 +36,7 @@ interface UserRow {
const db = new Kysely<DittoDB>({ const db = new Kysely<DittoDB>({
dialect: new DenoSqliteDialect({ dialect: new DenoSqliteDialect({
database: new Sqlite('data/db.sqlite3'), database: new Sqlite(Conf.dbPath),
}), }),
}); });