Suor/pg-bricks

Check connection configuration in configure()

vsenko opened this issue · 1 comments

It would be nice if configure() will try to connect to DB with provided configuration to verify connectivity. That way apps will have a simple mechanism to verify connectivity at start up and, in case it is needed, report problems to admins or users.

It could be done by extending Conf with something like this:

verifyConnection: function (callback) {
  pg.connect(this._connStr, function(error, client, done) {
    done();
    if (callback) {
      return callback(error);
    }
  });
}

And calling it in configure like that:

exports.configure = function (connStr, callback) {
    var conf = new Conf(connStr);
    conf.verifyConnection(function(error) {
        if (callback) {
            return callback(error, conf);
        }

        if (error) {
            throw error;
        }

        return conf;
    });
}
Suor commented

Definitely not including this by default. Why don't you just connect directly if you want to check it:

var db = require('pg-bricks').configure(connStr);
db.pg.connect(connStr, function (err, client, done) {
    // ...
    done(); 
})