fix jshint errors for lib/index.js

This commit is contained in:
Philipp Borgers 2013-01-21 14:52:00 +01:00
parent 22d8538879
commit ffe2c15a65

View File

@ -13,7 +13,7 @@ var PG = function(clientConstructor) {
EventEmitter.call(this); EventEmitter.call(this);
this.Client = clientConstructor; this.Client = clientConstructor;
this.Connection = require(__dirname + '/connection'); this.Connection = require(__dirname + '/connection');
this.Query = clientConstructor.Query this.Query = clientConstructor.Query;
this.defaults = defaults; this.defaults = defaults;
}; };
@ -25,8 +25,8 @@ PG.prototype.end = function() {
pool.drain(function() { pool.drain(function() {
pool.destroyAllNow(); pool.destroyAllNow();
}); });
}) });
} };
PG.prototype.connect = function(config, callback) { PG.prototype.connect = function(config, callback) {
var self = this; var self = this;
@ -42,14 +42,14 @@ PG.prototype.connect = function(config, callback) {
var poolName = typeof(c) === 'string' ? c : c.user+c.host+c.port+c.database; var poolName = typeof(c) === 'string' ? c : c.user+c.host+c.port+c.database;
var pool = pools[poolName]; var pool = pools[poolName];
if(pool) return pool.acquire(cb); if(pool) { return pool.acquire(cb); }
var pool = pools[poolName] = genericPool.Pool({ pool = pools[poolName] = genericPool.Pool({
name: poolName, name: poolName,
create: function(callback) { create: function(callback) {
var client = new self.Client(c); var client = new self.Client(c);
client.connect(function(err) { client.connect(function(err) {
if(err) return callback(err); if(err) { return callback(err); }
//handle connected client background errors by emitting event //handle connected client background errors by emitting event
//via the pg object and then removing errored client from the pool //via the pg object and then removing errored client from the pool
@ -74,17 +74,18 @@ PG.prototype.connect = function(config, callback) {
log: defaults.poolLog log: defaults.poolLog
}); });
return pool.acquire(cb); return pool.acquire(cb);
} };
// cancel the query runned by the given client // cancel the query runned by the given client
PG.prototype.cancel = function(config, client, query) { PG.prototype.cancel = function(config, client, query) {
var c = config; var c = config;
//allow for no config to be passed //allow for no config to be passed
if(typeof c === 'function') if(typeof c === 'function') {
c = defaults; c = defaults;
}
var cancellingClient = new this.Client(c); var cancellingClient = new this.Client(c);
cancellingClient.cancel(client, query); cancellingClient.cancel(client, query);
} };
module.exports = new PG(Client); module.exports = new PG(Client);