title: Manually promisifying pg.connect with Bluebird
body: <p>I want to promisify node-postgres' <code>pg.connect</code> method along with the inner <code>connection.query</code> method provided in the callback.</p>
  
  <p>I can <code>.promisify</code> the latter, but I need to implement the first one manually (if I'm missing something here, please explain).</p>
  
  <p>The thing is, I'm not sure if this code is correct or should be improved? The code is working, I just want to know if I'm using Bluebird as meant.</p>
  
  <pre><code>// aliases
  var asPromise = Promise.promisify;
  
  // save reference to original method
  var connect = pg.connect.bind(pg);
  
  // promisify method
  pg.connect = function (data) {
    var deferred = Promise.defer();
  
    connect(data, function promisify(err, connection, release) {
      if (err) return deferred.reject(err);
  
      // promisify query factory
      connection.query = asPromise(connection.query, connection);
  
      // resolve promised connection
      deferred.resolve([connection,release]);
    });
  
    return deferred.promise;
  };
  </code></pre>