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

Commit 89bfcb30 by Jan Aagaard Meier

Move pool initialization into a separate method that is called after the connect…

…ionmanager constructor is done. Closes #2048
1 parent 7b460dfe
......@@ -4,6 +4,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [FEATURE] Added to option of setting a timezone offset in the sequelize constructor (`timezone` option). This timezone is used when initializing a connection (using `SET TIME ZONE` or equivalent), and when converting a timestamp string from the DB to a JS date with mysql (postgres stores the timezone, so for postgres we rely on what's in the DB).
- [FEATURE] Allow setting plural and singular name on the model (`options.name` in `sequelize.define`) and in associations (`options.as`) to circumvent issues with weird pluralization.
- [BUG] Fixed problems with transcation parameter being removed / not passed on in associations [#1789](https://github.com/sequelize/sequelize/issues/1789) and [#1968](https://github.com/sequelize/sequelize/issues/1968)
- [BUG] Fix problem with minConnections. [#2048](https://github.com/sequelize/sequelize/issues/2048)
- [INTERNALS] Replaced lingo with inflection
- [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`
......
......@@ -39,6 +39,21 @@ ConnectionManager = function(dialect, sequelize) {
if (config.pool.maxConnections) config.pool.max = config.pool.maxConnections;
if (config.pool.minConnections) config.pool.min = config.pool.minConnections;
this.onProcessExit = function() {
// Cleanup
self.pool.drain();
return;
}.bind(this);
process.on('exit', this.onProcessExit);
};
// This cannot happen in the constructor because the user can specify a min. number of connections to have in the pool
// If he does this, generic-pool will try to call connect before the dialect-specific connection manager has been correctly set up
ConnectionManager.prototype.initPools = function () {
var self = this
, config = this.config;
if (config.replication) {
var reads = 0
, writes = 0;
......@@ -149,13 +164,6 @@ ConnectionManager = function(dialect, sequelize) {
});
}
this.onProcessExit = function() {
// Cleanup
self.pool.drain();
return;
}.bind(this);
process.on('exit', this.onProcessExit);
};
ConnectionManager.prototype.getConnection = function(options) {
......@@ -190,4 +198,4 @@ ConnectionManager.prototype.$validate = function(connection) {
return this.dialect.connectionManager.validate(connection);
};
module.exports = ConnectionManager;
\ No newline at end of file
module.exports = ConnectionManager;
......@@ -8,6 +8,7 @@ var _ = require('lodash')
var MariaDialect = function(sequelize) {
this.sequelize = sequelize;
this.connectionManager = new ConnectionManager(this, sequelize);
this.connectionManager.initPools();
};
MariaDialect.prototype = _.defaults({
......@@ -16,4 +17,4 @@ MariaDialect.prototype = _.defaults({
MariaDialect.prototype.Query = Query;
module.exports = MariaDialect;
\ No newline at end of file
module.exports = MariaDialect;
......@@ -8,6 +8,7 @@ var _ = require('lodash')
var MysqlDialect = function(sequelize) {
this.sequelize = sequelize;
this.connectionManager = new ConnectionManager(this, sequelize);
this.connectionManager.initPools();
};
MysqlDialect.prototype.supports = _.defaults({
......@@ -19,4 +20,4 @@ MysqlDialect.prototype.supports = _.defaults({
MysqlDialect.prototype.Query = Query;
module.exports = MysqlDialect;
\ No newline at end of file
module.exports = MysqlDialect;
......@@ -8,6 +8,7 @@ var _ = require('lodash')
var PostgresDialect = function(sequelize) {
this.sequelize = sequelize;
this.connectionManager = new ConnectionManager(this, sequelize);
this.connectionManager.initPools();
};
PostgresDialect.prototype.supports = _.defaults({
......@@ -20,4 +21,4 @@ PostgresDialect.prototype.supports = _.defaults({
PostgresDialect.prototype.Query = Query;
module.exports = PostgresDialect;
\ No newline at end of file
module.exports = PostgresDialect;
......@@ -26,6 +26,21 @@ var qq = function(str) {
describe(Support.getTestDialectTeaser("Sequelize"), function () {
describe('constructor', function() {
if (dialect !== 'sqlite') {
it('should work with minConnections', function () {
var ConnectionManager = require(__dirname + '/../lib/dialects/' + dialect + '/connection-manager.js')
, connectionSpy = ConnectionManager.prototype.connect = chai.spy(ConnectionManager.prototype.connect);
var sequelize = Support.createSequelizeInstance({
dialect: dialect,
pool: {
minConnections: 2
}
});
expect(connectionSpy).to.have.been.called.twice;
});
}
it('should pass the global options correctly', function(done) {
var sequelize = Support.createSequelizeInstance({ logging: false, define: { underscored:true } })
, DAO = sequelize.define('dao', {name: DataTypes.STRING})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!