-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgres.js
More file actions
26 lines (25 loc) · 727 Bytes
/
Postgres.js
File metadata and controls
26 lines (25 loc) · 727 Bytes
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
var pg = require('pg')
module.exports = function(host, db, user, pass) {
var conString = "postgres://" + user + ":" + pass + "@" + host + "/" + db;
console.log(conString);
return {
exec: function(query, callback) {
pg.connect(conString, function(err, client, done) {
if (err) {
console.log("PostgreSQL connection error!");
return;
}
client.query(query, [], function(err, result) {
done();
if (err) {
console.log("Query error!\n" + err);
if (callback)
callback("Query error!\n" + err);
} else
if (callback)
callback(undefined, result.rows);
})
})
}
}
}