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

Commit ec7ef9a5 by Mick Hansen

Merge branch 'master' of github.com:sequelize/sequelize

2 parents 034da3f4 46da0e5d
Notice: All 1.7.x changes are present in 2.0.x aswell Notice: All 1.7.x changes are present in 2.0.x aswell
# v1.7.0 (next) # v1.7.0 (next)
- [FEATURE] covers more advanced include cases with limiting and filtering - [FEATURE] covers more advanced include cases with limiting and filtering (specifically cases where a include would be in the subquery but its child include wouldnt be, for cases where a 1:1 association had a 1:M association as a nested include)
- [BUG] fixes issue where connection would timeout before calling COMMIT resulting in data never reaching the database [#1429](https://github.com/sequelize/sequelize/pull/1429)
# v1.7.0-rc9 # v1.7.0-rc9
- [PERFORMANCE] fixes performance regression introduced in rc7 - [PERFORMANCE] fixes performance regression introduced in rc7
......
var Query = require("./query")
var Query = require("./query") , Utils = require("../../utils")
, Utils = require("../../utils") , ConnectionParameters = require('pg/lib/connection-parameters')
module.exports = (function() { module.exports = (function() {
var ConnectorManager = function(sequelize, config) { var ConnectorManager = function(sequelize, config) {
...@@ -16,13 +16,6 @@ module.exports = (function() { ...@@ -16,13 +16,6 @@ module.exports = (function() {
// https://github.com/brianc/node-postgres/issues/166#issuecomment-9514935 // https://github.com/brianc/node-postgres/issues/166#issuecomment-9514935
this.pg.types.setTypeParser(20, String); this.pg.types.setTypeParser(20, String);
// set pooling parameters if specified
if (this.pooling) {
this.pg.defaults.poolSize = this.config.pool.maxConnections || 10
this.pg.defaults.poolIdleTimeout = this.config.pool.maxIdleTime || 30000
this.pg.defaults.reapIntervalMillis = this.config.pool.reapInterval || 1000
}
this.disconnectTimeoutId = null this.disconnectTimeoutId = null
this.pendingQueries = 0 this.pendingQueries = 0
this.clientDrained = true this.clientDrained = true
...@@ -31,7 +24,7 @@ module.exports = (function() { ...@@ -31,7 +24,7 @@ module.exports = (function() {
this.onProcessExit = function () { this.onProcessExit = function () {
this.disconnect() this.disconnect()
}.bind(this); }.bind(this);
process.on('exit', this.onProcessExit) process.on('exit', this.onProcessExit)
} }
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype) Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
...@@ -89,7 +82,16 @@ module.exports = (function() { ...@@ -89,7 +82,16 @@ module.exports = (function() {
this.isConnecting = true this.isConnecting = true
this.isConnected = false this.isConnected = false
var uri = this.sequelize.getQueryInterface().QueryGenerator.databaseConnectionUri(this.config) var uri = this.sequelize.getQueryInterface().QueryGenerator.databaseConnectionUri(this.config)
, config = new ConnectionParameters(uri)
// set pooling parameters if specified
if (this.pooling) {
config.poolSize = this.config.pool.maxConnections || 10
config.poolIdleTimeout = this.config.pool.maxIdleTime || 30000
config.reapIntervalMillis = this.config.pool.reapInterval || 1000
config.uuid = this.config.uuid
}
var connectCallback = function(err, client, done) { var connectCallback = function(err, client, done) {
self.isConnecting = false self.isConnecting = false
...@@ -142,7 +144,7 @@ module.exports = (function() { ...@@ -142,7 +144,7 @@ module.exports = (function() {
if (this.pooling) { if (this.pooling) {
// acquire client from pool // acquire client from pool
this.pg.connect(uri, connectCallback) this.pg.connect(config, connectCallback)
} else { } else {
if (!!this.client) { if (!!this.client) {
connectCallback(null, this.client) connectCallback(null, this.client)
...@@ -151,13 +153,13 @@ module.exports = (function() { ...@@ -151,13 +153,13 @@ module.exports = (function() {
var responded = false var responded = false
this.client = new this.pg.Client(uri) this.client = new this.pg.Client(config)
this.client.connect(function(err, client, done) { this.client.connect(function(err, client, done) {
responded = true responded = true
connectCallback(err, client || self.client, done) connectCallback(err, client || self.client, done)
}) })
// If we didn't ever hear from the client.connect() callback the connection timedout, node-postgres does not treat this as an error since no active query was ever emitted // If we didn't ever hear from the client.connect() callback the connection timeout, node-postgres does not treat this as an error since no active query was ever emitted
this.client.on('end', function () { this.client.on('end', function () {
if (!responded) { if (!responded) {
connectCallback(new Error('Connection timed out')) connectCallback(new Error('Connection timed out'))
......
...@@ -22,8 +22,9 @@ TransactionManager.prototype.getConnectorManager = function(uuid) { ...@@ -22,8 +22,9 @@ TransactionManager.prototype.getConnectorManager = function(uuid) {
{}, {},
Utils._.clone(config.pool || {}), Utils._.clone(config.pool || {}),
{ {
maxConnections: 0, minConnections: 1,
useReplicaton: false maxConnections: 1,
useReplicaton: false
} }
) )
config.keepDefaultTimezone = true config.keepDefaultTimezone = true
......
...@@ -86,4 +86,4 @@ Transaction.prototype.cleanup = function() { ...@@ -86,4 +86,4 @@ Transaction.prototype.cleanup = function() {
var onError = function(err) { var onError = function(err) {
this.emit('error', err) this.emit('error', err)
} }
\ No newline at end of file
...@@ -116,4 +116,35 @@ describe(Support.getTestDialectTeaser("Sequelize#transaction"), function () { ...@@ -116,4 +116,35 @@ describe(Support.getTestDialectTeaser("Sequelize#transaction"), function () {
}).done(done) }).done(done)
}) })
}) })
describe('complex long running example', function() {
it("works with promise syntax", function(done) {
Support.prepareTransactionTest(this.sequelize, function(sequelize) {
var Test = sequelize.define('Test', {
id: { type: Support.Sequelize.INTEGER, primaryKey: true, autoIncrement: true},
name: { type: Support.Sequelize.STRING }
})
sequelize
.sync({ force: true })
.then(function() {
sequelize.transaction(function(transaction) {
Test
.create({ name: 'Peter' }, { transaction: transaction })
.then(function() {
setTimeout(function() {
transaction
.commit()
.then(function() { return Test.count() })
.then(function(count) {
expect(count).to.equal(1)
done()
})
}, 1000)
})
})
})
})
})
})
}) })
...@@ -60,12 +60,13 @@ describe(Support.getTestDialectTeaser("TransactionManager"), function () { ...@@ -60,12 +60,13 @@ describe(Support.getTestDialectTeaser("TransactionManager"), function () {
} }
Object.keys(this.sequelize.config.pool || {}).forEach(function(key) { Object.keys(this.sequelize.config.pool || {}).forEach(function(key) {
if (key !== 'maxConnections') { if (['minConnections', 'maxConnections'].indexOf(key) === -1) {
expect(connectorManager.config.pool[key]).to.equal(self.sequelize.config.pool[key]) expect(connectorManager.config.pool[key]).to.equal(self.sequelize.config.pool[key])
} }
}) })
expect(connectorManager.config.pool.maxConnections).to.equal(0) expect(connectorManager.config.pool.minConnections).to.equal(1)
expect(connectorManager.config.pool.maxConnections).to.equal(1)
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!