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