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

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