-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
49 lines (40 loc) · 1.07 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SETUP DB, LOCALHOST AND HEROKU
var db = {};
var pg = require('pg');
// LOCALHOST
// db.config = {
// database: "pitchforks",
// port: 5432,
// host: "localhost",
// // user: "postgres"
// };
// db.connect = function(runAfterConnecting) {
// pg.connect(db.config, function(err, client, done){
// if (err) {
// console.error("OOOPS!!! SOMETHING WENT WRONG!", err);
// }
// runAfterConnecting(client);
// done();
// });
// };
// LOCALHOST AND HEROKU
db.query = function(statement, params, callback){
db.connect(function(client){
client.query(statement, params, callback);
});
};
// HEROKU
db.config = {}
db.connect = function(runAfterConnecting) {
console.log(process.env.DATABASE_URL);
pg.connect(process.env.DATABASE_URL, function(err, client, done){
if (err) {
console.error("OOOPS!!! SOMETHING WENT WRONG!", err);
}
runAfterConnecting(client);
done();
});
};
// Heroku DB Link
// postgres://jskkmojmrdkgwr:lfooOMVWDrT60HKMYCWxLW2VNV@ec2-54-163-250-41.compute-1.amazonaws.com:5432/d1028jfm8s0pe2
module.exports = db;