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

Commit 103ed7cb by Jan Aagaard Meier

use connect function

1 parent 0d0e4c04
Showing with 17 additions and 19 deletions
...@@ -33,7 +33,7 @@ module.exports = (function() { ...@@ -33,7 +33,7 @@ module.exports = (function() {
config.replication.read[i] = Utils._.defaults(config.replication.read[i], { config.replication.read[i] = Utils._.defaults(config.replication.read[i], {
host: this.config.host, host: this.config.host,
port: this.config.port, port: this.config.port,
user: this.config.username, username: this.config.username,
password: this.config.password, password: this.config.password,
database: this.config.database database: this.config.database
}); });
...@@ -41,7 +41,7 @@ module.exports = (function() { ...@@ -41,7 +41,7 @@ module.exports = (function() {
config.replication.write = Utils._.defaults(config.replication.write, { config.replication.write = Utils._.defaults(config.replication.write, {
host: this.config.host, host: this.config.host,
port: this.config.port, port: this.config.port,
user: this.config.username, username: this.config.username,
password: this.config.password, password: this.config.password,
database: this.config.database database: this.config.database
}); });
...@@ -72,11 +72,10 @@ module.exports = (function() { ...@@ -72,11 +72,10 @@ module.exports = (function() {
if (reads >= self.config.replication.read.length) reads = 0; if (reads >= self.config.replication.read.length) reads = 0;
var config = self.config.replication.read[reads++]; var config = self.config.replication.read[reads++];
var connection = mysql.createConnection(config) connect.call(self, function (err, connection) {
connection.queryType = 'read'; connection.queryType = 'read'
self.isConnecting = false done(null, connection)
}, config);
done(null, connection)
}, },
destroy: function(client) { destroy: function(client) {
disconnect.call(self, client) disconnect.call(self, client)
...@@ -88,11 +87,10 @@ module.exports = (function() { ...@@ -88,11 +87,10 @@ module.exports = (function() {
write: Pooling.Pool({ write: Pooling.Pool({
name: 'sequelize-write', name: 'sequelize-write',
create: function (done) { create: function (done) {
var connection = mysql.createConnection(self.config.replication.write) connect.call(self, function (err, connection) {
connection.queryType = 'write'; connection.queryType = 'write'
self.isConnecting = false done(null, connection)
}, self.config.replication.write);
done(null, connection)
}, },
destroy: function(client) { destroy: function(client) {
disconnect.call(self, client) disconnect.call(self, client)
...@@ -101,7 +99,6 @@ module.exports = (function() { ...@@ -101,7 +99,6 @@ module.exports = (function() {
min: self.poolCfg.minConnections, min: self.poolCfg.minConnections,
idleTimeoutMillis: self.poolCfg.maxIdleTime idleTimeoutMillis: self.poolCfg.maxIdleTime
}) })
}; };
} else if (this.poolCfg) { } else if (this.poolCfg) {
//the user has requested pooling, so create our connection pool //the user has requested pooling, so create our connection pool
...@@ -224,13 +221,14 @@ module.exports = (function() { ...@@ -224,13 +221,14 @@ module.exports = (function() {
}) })
} }
var connect = function(done) { var connect = function(done, config) {
var _config = config || this.config
var connection = mysql.createConnection({ var connection = mysql.createConnection({
host: this.config.host, host: config.host,
port: this.config.port, port: config.port,
user: this.config.username, user: config.username,
password: this.config.password, password: config.password,
database: this.config.database database: config.database
}) })
// client.setMaxListeners(self.maxConcurrentQueries) // client.setMaxListeners(self.maxConcurrentQueries)
this.isConnecting = false this.isConnecting = false
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!