-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
50 lines (39 loc) · 1.1 KB
/
db.js
File metadata and controls
50 lines (39 loc) · 1.1 KB
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
50
const pg = require('pg');
const url = require('url');
if( process.env.DATABASE_URL ){
//we need to take apart the url so we can set the appropriate configs
const params = url.parse(process.env.DATABASE_URL);
const auth = params.auth.split(':');
//make the configs object
var configs = {
user: auth[0],
password: auth[1],
host: params.hostname,
port: params.port,
database: params.pathname.split('/')[1],
ssl: true
};
} else {
var configs = {
user: 'angkiki',
host: '127.0.0.1',
database: 'project_2',
port: 5432
};
}
const poolObj = new pg.Pool(configs);
poolObj.on('error', function (err) {
console.log('idle client error', err.message, err.stack);
});
const userModel = require('./models/user');
const bookmarkModel = require('./models/bookmark');
const linkModel = require('./models/link');
const userObj = userModel(poolObj);
const bookmarkObj = bookmarkModel(poolObj);
const linkObj = linkModel(poolObj);
module.exports = {
user: userObj,
bookmark: bookmarkObj,
link: linkObj,
pool: poolObj
};