-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
12 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,12 +1,22 @@ | ||
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: { | ||
extension: "ts", | ||
}, | ||
} | ||
|
||
const config: Knex.Config = process.env.DATABASE_URL ? PG_CONFIG : SQLITE_CONFIG | ||
|
||
export default config |
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,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() |