-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpgp_db.js
More file actions
57 lines (52 loc) · 1.71 KB
/
pgp_db.js
File metadata and controls
57 lines (52 loc) · 1.71 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
52
53
54
55
56
57
const pgPromise = require('pg-promise')
const options = {
// Initialization Options
promiseLib: pgPromise.promise,
capSQL: true,
query (e) {
var date = new Date()
var messageout = { 'hasExecuted': e.client.hasExecuted }
// Exclude the big chunky query:
if (e.query.match(/CONCAT.*pronamespace = n.oid/)) {
messageout.query = 'List all functions'
} else if (e.query.match(/WHERE proname LIKE/)) {
messageout.query = 'Match function schema'
} else {
messageout.query = e.query
// messageout.db = { client: e.client.user, database: e.client.database, host: e.client.host }
}
console.log(date.toISOString() + '\t' + JSON.stringify(messageout) + '\n')
},
error (err, e) {
var date = new Date()
// Exclude the big chunky query:
// console.log(JSON.stringify(err))
var messageout = { 'error': JSON.stringify(err), 'query': e.query }
// messageout.db = { 'client': e.client.user, 'database': e.client.database, 'host': e.client.host }
console.log(date.toISOString() + ' ' + JSON.stringify(messageout))
}
}
const pgp = require('pg-promise')(options)
/**
* Create connection object to open database connection to the required database.
* @param {req} An http Request object passed from the calling function.
* @returns {Database} A database connection.
*/
function dbheader () {
var out = {
'host': process.env.RDS_HOSTNAME,
'user': process.env.RDS_USERNAME,
'database': process.env.RDS_DATABASE,
'password': process.env.RDS_PASSWORD,
'port': process.env.RDS_PORT,
'ssl': {
'rejectUnauthorized': false
},
'query_timeout': 15000
}
return pgp(out)
}
module.exports = {
dbheader: dbheader,
dboptions: options
}