Skip to content

Commit

Permalink
Merge pull request #20 from GSG-K3/intializedatabase
Browse files Browse the repository at this point in the history
intilaize database #19
  • Loading branch information
kholoudfann authored Feb 26, 2020
2 parents 426e19b + 4b7c2ad commit 659d01c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions database/config/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require("fs");
const path = require("path");

const dbConnection = require("./connection.js");


const dbBuild = () => {
const sqlPath = readFileSync (join(__dirname, "build.sql")).toString();
return dbConnection.query(sql,( err,res)=>{
if(err) throw new Error('error build.js');
else console.log('build sucsess');

});
};



module.exports = {dbBuild};
19 changes: 19 additions & 0 deletions database/config/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require("env2")("./config.env");
const { Pool } = require("pg");
const url = '';

let connectionString = process.env.DB_URL;

if (process.env.NODE_ENV === "test") {
connectionString = process.env.TEST_DB_URL;
}
if (!connectionString) {
throw new Error("please set a DB_URL env variable");

}
const options = {
connectionString: url,
sll: true
};

module.exports = new Pool(options);

0 comments on commit 659d01c

Please sign in to comment.