不要怂,就是干,撸起袖子干!

Commit 07273911 by Sascha Depold

refactoring

1 parent 00594184
Showing with 15 additions and 15 deletions
...@@ -10,20 +10,6 @@ var ConnectorManager = module.exports = function(config) { ...@@ -10,20 +10,6 @@ var ConnectorManager = module.exports = function(config) {
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50) this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
} }
ConnectorManager.prototype.connect = function() {
var self = this
this.client = require("mysql").createClient({
user: this.config.username,
password: this.config.password,
host: this.config.host,
port: this.config.port,
database: this.config.database
})
this.client.setMaxListeners(this.maxConcurrentQueries)
}
ConnectorManager.prototype.query = function(sql, callee, options) { ConnectorManager.prototype.query = function(sql, callee, options) {
if(!this.isConnected) this.connect() if(!this.isConnected) this.connect()
...@@ -37,6 +23,20 @@ ConnectorManager.prototype.query = function(sql, callee, options) { ...@@ -37,6 +23,20 @@ ConnectorManager.prototype.query = function(sql, callee, options) {
return queueItem.query return queueItem.query
} }
ConnectorManager.prototype.connect = function() {
var self = this
this.client = require("mysql").createClient({
user: this.config.username,
password: this.config.password,
host: this.config.host,
port: this.config.port,
database: this.config.database
})
this.client.setMaxListeners(this.maxConcurrentQueries)
}
ConnectorManager.prototype.disconnect = function() { ConnectorManager.prototype.disconnect = function() {
var self = this var self = this
this.client.end(function() { self.client = null }) this.client.end(function() { self.client = null })
...@@ -101,7 +101,7 @@ ConnectorManager.prototype.__defineGetter__('isConnected', function() { ...@@ -101,7 +101,7 @@ ConnectorManager.prototype.__defineGetter__('isConnected', function() {
ConnectorManager.prototype._disconnectIfNoConnections = function() { ConnectorManager.prototype._disconnectIfNoConnections = function() {
var self = this var self = this
this.disconnectTimeoutId && clearTimeout(this.disconnectTimeoutId) this.disconnectTimeoutId && clearTimeout(this.disconnectTimeoutId)
this.disconnectTimeoutId = setTimeout(function() { this.disconnectTimeoutId = setTimeout(function() {
self.isConnected && self.hasNoConnections && self.disconnect() self.isConnected && self.hasNoConnections && self.disconnect()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!