forked from hasadna/OpenPension-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
44 lines (35 loc) · 769 Bytes
/
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
var pg = require('pg');
var config = require('./config')
var db = {};
db.pg = function() {
this.client = new pg.Client(config.connection_string);
this.client.connect();
};
db.pg.prototype = {
querys: function(sql,callback) {
var self = this;
this.client.query(sql, function(err, result) {
if(err) {
callback(err);
return;
}
callback(null, result.rows);
self.client.end();
});
},
multiple_queries: function(sql,callback) {
this.client.query(sql, function(err, result) {
if(err) {
callback(err);
return;
}
callback(null, result.rows);
});
},
end: function(sql,callback) {
this.client.end();
}
};
exports.open = function() {
return new db.pg();
};