diff --git a/index.js b/index.js index 3f7dc57..442bd84 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ function PostgresDB(options) { this.closed = false; - this.pg_config = options; + this.pool = new pg.Pool(options); }; module.exports = PostgresDB; @@ -17,6 +17,8 @@ PostgresDB.prototype = Object.create(DB.prototype); PostgresDB.prototype.close = function(callback) { this.closed = true; + this.pool.end(); + if (callback) callback(); }; @@ -39,7 +41,7 @@ PostgresDB.prototype.commit = function(collection, id, op, snapshot, options, ca * } * snapshot: PostgresSnapshot */ - pg.connect(this.pg_config, function(err, client, done) { + this.pool.connect(function(err, client, done) { if (err) { done(client); callback(err); @@ -123,7 +125,7 @@ PostgresDB.prototype.commit = function(collection, id, op, snapshot, options, ca // snapshot). A snapshot with a version of zero is returned if the docuemnt // has never been created in the database. PostgresDB.prototype.getSnapshot = function(collection, id, fields, options, callback) { - pg.connect(this.pg_config, function(err, client, done) { + this.pool.connect(function(err, client, done) { if (err) { done(client); callback(err); @@ -173,7 +175,7 @@ PostgresDB.prototype.getSnapshot = function(collection, id, fields, options, cal // // Callback should be called as callback(error, [list of ops]); PostgresDB.prototype.getOps = function(collection, id, from, to, options, callback) { - pg.connect(this.pg_config, function(err, client, done) { + this.pool.connect(function(err, client, done) { if (err) { done(client); callback(err); diff --git a/package.json b/package.json index 3b1f446..bd89bc9 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "keywords": ["sharedb", "sharejs", "share", "postgres"], "repository": "share/sharedb-postgres", "dependencies": { - "pg": "^4.5.1", + "pg": "^7.4.1", "sharedb": "^1.0.0-beta.7" } -} +} \ No newline at end of file