Skip to content

Commit

Permalink
Merge branch 'master' into database-planning
Browse files Browse the repository at this point in the history
  • Loading branch information
trishtracking committed Oct 19, 2020
2 parents 251274f + 172b368 commit 6ede1b3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/database/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require("path");
const fs = require("fs");
const database = require("./connection");

const filepath = path.join(__dirname, "init.sql");
const initSQL = fs.readFileSync(filepath, "utf-8");

const build = () => {
return database
.query(initSQL)
.then(() => {
console.log("Database built");
db.end();
})
.catch(console.log);
};

module.exports = build;
14 changes: 14 additions & 0 deletions src/database/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const pg = require("pg");
const dotenv = require("dotenv").config();

let connectionString = process.env.DATABASE_URL;

if (process.env.NODE_ENV === "test") {
connectionString = process.env.TEST_DATABASE_URL;
}

const database = new pg.Pool({
connectionString,
});

module.exports = database;

0 comments on commit 6ede1b3

Please sign in to comment.