diff --git a/knexfile.ts b/knexfile.ts index d3b638c..45e907c 100644 --- a/knexfile.ts +++ b/knexfile.ts @@ -1,7 +1,15 @@ import type { Knex } from "knex" require("dotenv").config() -const config: Knex.Config = { +// used for preview / if DATABASE_URL not set +const SQLITE_CONFIG: Knex.Config = { + client: "sqlite3", + connection: { + filename: ":memory:", + }, +} + +const PG_CONFIG = { client: "postgresql", connection: process.env.DATABASE_URL, migrations: { @@ -9,4 +17,6 @@ const config: Knex.Config = { }, } +const config: Knex.Config = process.env.DATABASE_URL ? PG_CONFIG : SQLITE_CONFIG + export default config diff --git a/src/knex/db.ts b/src/knex/db.ts index ffb319a..dd867d3 100644 --- a/src/knex/db.ts +++ b/src/knex/db.ts @@ -1,18 +1,8 @@ -import type { Knex } from "knex" import knex from "knex" import config from "../../knexfile" -// used for preview / if DATABASE_URL not set -const DEFAULT_CONFIG: Knex.Config = { - client: "sqlite3", - connection: { - filename: ":memory:", - }, -} - const newDb = () => { - const cfg = process.env.DATABASE_URL ? config : DEFAULT_CONFIG - return knex(cfg) + return knex(config) } export const db = newDb()