Skip to content

Commit

Permalink
fix: unhandled error event on connection
Browse files Browse the repository at this point in the history
Signed-off-by: William F Wheeler II <bill@quickbrownfoxlabs.com>
  • Loading branch information
bill-kitsune committed Jan 27, 2018
1 parent 8c4fb9f commit c19d201
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var PgDriver = Base.extend({
this.internals = intern;
this.connection = connection;
this.schema = schema || "public";
this.connection.connect();
},

startMigration: function(cb){
Expand Down Expand Up @@ -517,7 +516,12 @@ exports.connect = function(config, intern, callback) {

if (config.native) { pg = pg.native; }
var db = config.db || new pg.Client(config);
callback(null, new PgDriver(db, config.schema, intern));
db.connect(function(err) {
if(err) {
callback(err);
}
callback(null, new PgDriver(db, config.schema, intern));
});
};

exports.base = PgDriver;
10 changes: 10 additions & 0 deletions test/pg_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ vows.describe('pg').addBatch({
db = _db;
}
}
}).addBatch({
'connect error': {
topic: function () {
driver.connect({host: 'fakehost'}, internals, this.callback);
},

'shows connection error': function (err, _db) {
assert.isNotNull(err);
}
}
}).addBatch({
'createTable': {
topic: function() {
Expand Down

0 comments on commit c19d201

Please sign in to comment.