-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
53 lines (45 loc) · 1.32 KB
/
db.js
File metadata and controls
53 lines (45 loc) · 1.32 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
51
const pg = require('pg');
const category = require('./models/category');
const report = require('./models/report');
const reportResults = require('./models/report');
const user = require('./models/user');
const admin = require('./models/admin');
let dbConfigs, queryConfigs;
if (process.env.NODE_ENV == 'production') {
dbConfigs = {
connectionString: process.env.DATABASE_URL,
ssl: true
};
queryConfigs = {
connectionString: process.env.HEROKU_POSTGRESQL_COBALT_URL,
ssl: true
};
} else {
dbConfigs = {
user: process.env.METADATA_DB_USER,
host: process.env.METADATA_DB_HOST,
database: process.env.METADATA_DB_DATABASE,
port: process.env.METADATA_DB_PORT
};
queryConfigs = {
user: process.env.QUERY_DB_USER,
host: process.env.QUERY_DB_HOST,
database: process.env.QUERY_DB_DATABASE,
port: process.env.QUERY_DB_PORT
};
}
const dbPool = new pg.Pool(dbConfigs);
const queryPool = new pg.Pool(queryConfigs);
dbPool.on('error', function (err) {
console.log('idle client error', err.message, err.stack);
});
queryPool.on('error', function (err) {
console.log('idle client error', err.message, err.stack);
});
module.exports = {
categoryDB: category(dbPool),
reportDB: report(dbPool),
reportResultsDB: reportResults(queryPool),
userDB: user(dbPool),
adminDB: admin(dbPool)
}