@@ -10,13 +10,16 @@ function PostgresDB(options) {
10
10
this . closed = false ;
11
11
12
12
this . pg_config = options ;
13
+ this . pool = new pg . Pool ( this . pg_config )
13
14
} ;
14
15
module . exports = PostgresDB ;
15
16
16
17
PostgresDB . prototype = Object . create ( DB . prototype ) ;
17
18
18
19
PostgresDB . prototype . close = function ( callback ) {
19
20
this . closed = true ;
21
+ this . pool . end ( )
22
+
20
23
if ( callback ) callback ( ) ;
21
24
} ;
22
25
@@ -39,7 +42,7 @@ PostgresDB.prototype.commit = function(collection, id, op, snapshot, options, ca
39
42
* }
40
43
* snapshot: PostgresSnapshot
41
44
*/
42
- pg . connect ( this . pg_config , function ( err , client , done ) {
45
+ this . pool . connect ( function ( err , client , done ) {
43
46
if ( err ) {
44
47
done ( client ) ;
45
48
callback ( err ) ;
@@ -123,7 +126,7 @@ PostgresDB.prototype.commit = function(collection, id, op, snapshot, options, ca
123
126
// snapshot). A snapshot with a version of zero is returned if the docuemnt
124
127
// has never been created in the database.
125
128
PostgresDB . prototype . getSnapshot = function ( collection , id , fields , options , callback ) {
126
- pg . connect ( this . pg_config , function ( err , client , done ) {
129
+ this . pool . connect ( function ( err , client , done ) {
127
130
if ( err ) {
128
131
done ( client ) ;
129
132
callback ( err ) ;
@@ -173,7 +176,7 @@ PostgresDB.prototype.getSnapshot = function(collection, id, fields, options, cal
173
176
//
174
177
// Callback should be called as callback(error, [list of ops]);
175
178
PostgresDB . prototype . getOps = function ( collection , id , from , to , options , callback ) {
176
- pg . connect ( this . pg_config , function ( err , client , done ) {
179
+ this . pool . connect ( function ( err , client , done ) {
177
180
if ( err ) {
178
181
done ( client ) ;
179
182
callback ( err ) ;
0 commit comments