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

Commit 8e869b22 by Mick Hansen

Merge branch 'master' into milestones/2.0.0

2 parents 5a6cf750 e44912e9
...@@ -7,6 +7,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -7,6 +7,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- fixes bug with mysql replication and pool settings [#1251](https://github.com/sequelize/sequelize/pull/1251) - fixes bug with mysql replication and pool settings [#1251](https://github.com/sequelize/sequelize/pull/1251)
- through models created by N:M associations no longer inherit hooks [#1263](https://github.com/sequelize/sequelize/issues/1263) - through models created by N:M associations no longer inherit hooks [#1263](https://github.com/sequelize/sequelize/issues/1263)
- .col()/.literal()/etc now works with findAll [#1249](https://github.com/sequelize/sequelize/issues/1249) - .col()/.literal()/etc now works with findAll [#1249](https://github.com/sequelize/sequelize/issues/1249)
- now currectly handles connection timeouts as errors [#1207](https://github.com/sequelize/sequelize/issues/1207)
# v2.0.0 (alpha1) # # v2.0.0 (alpha1) #
- [FEATURE] async validations. [#580](https://github.com/sequelize/sequelize/pull/580). thanks to Interlock - [FEATURE] async validations. [#580](https://github.com/sequelize/sequelize/pull/580). thanks to Interlock
......
...@@ -151,7 +151,6 @@ module.exports = (function() { ...@@ -151,7 +151,6 @@ module.exports = (function() {
.create(values, fieldsOrOptions) .create(values, fieldsOrOptions)
.proxy(emitter, { events: ['error', 'sql'] }) .proxy(emitter, { events: ['error', 'sql'] })
.success(function(newAssociatedObject) { .success(function(newAssociatedObject) {
console.log(self.accessors.set, !!newAssociatedObject, !!options.transaction);
instance[self.accessors.set](newAssociatedObject, options) instance[self.accessors.set](newAssociatedObject, options)
.proxy(emitter) .proxy(emitter)
}) })
......
...@@ -287,16 +287,15 @@ module.exports = (function() { ...@@ -287,16 +287,15 @@ module.exports = (function() {
self self
.QueryInterface .QueryInterface
.createTable(self.getTableName(), self.attributes, options) .createTable(self.getTableName(), self.attributes, options)
.proxy(emitter, {events: ['error', 'sql']})
.success(function() { emitter.emit('success', self) }) .success(function() { emitter.emit('success', self) })
.error(function(err) { emitter.emit('error', err) })
.on('sql', function(sql) { emitter.emit('sql', sql) })
} }
if (options.force) { if (options.force) {
self self
.drop(options) .drop(options)
.proxy(emitter, {events: ['error', 'sql']})
.success(doQuery) .success(doQuery)
.error(function(err) { emitter.emit('error', err) })
} else { } else {
doQuery() doQuery()
} }
......
...@@ -148,11 +148,22 @@ module.exports = (function() { ...@@ -148,11 +148,22 @@ module.exports = (function() {
connectCallback(null, this.client) connectCallback(null, this.client)
} else { } else {
//create one-off client //create one-off client
var responded = false
this.client = new this.pg.Client(uri) this.client = new this.pg.Client(uri)
this.client.connect(function(err, client, done) { this.client.connect(function(err, client, done) {
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
this.client.on('end', function () {
if (!responded) {
connectCallback(new Error('Connection timed out'))
}
})
// Closes a client correctly even if we have backed up queries // Closes a client correctly even if we have backed up queries
// https://github.com/brianc/node-postgres/pull/346 // https://github.com/brianc/node-postgres/pull/346
this.client.on('drain', function() { this.client.on('drain', function() {
......
...@@ -902,7 +902,6 @@ module.exports = (function() { ...@@ -902,7 +902,6 @@ module.exports = (function() {
}, options || {}) }, options || {})
var execQuery = function(emitter) { var execQuery = function(emitter) {
var query = null
if (Array.isArray(sqlOrQueryParams)) { if (Array.isArray(sqlOrQueryParams)) {
if (sqlOrQueryParams.length === 1) { if (sqlOrQueryParams.length === 1) {
...@@ -920,19 +919,19 @@ module.exports = (function() { ...@@ -920,19 +919,19 @@ module.exports = (function() {
emitter emitter
.query .query
.proxy(emitter)
.success(function(obj) { .success(function(obj) {
options.success && options.success(obj) if (options.success) {
options.success(obj)
}
this.emit(methodName, null) this.emit(methodName, null)
emitter.emit('success', obj)
}.bind(this)) }.bind(this))
.error(function(err) { .error(function(err) {
options.error && options.error(err) if (options.error) {
options.error(err)
}
this.emit(methodName, err) this.emit(methodName, err)
emitter.emit('error', err)
}.bind(this)) }.bind(this))
.on('sql', function(sql) {
emitter.emit('sql', sql)
})
}.bind(this) }.bind(this)
if (!!emitter) { if (!!emitter) {
......
...@@ -397,14 +397,15 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -397,14 +397,15 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
if (dialect !== "sqlite") { if (dialect !== "sqlite") {
it("fails with incorrect database credentials", function(done) { it("fails with incorrect database credentials (1)", function(done) {
this.sequelizeWithInvalidCredentials = new Sequelize("omg", "bar", null, this.sequelize.options) this.sequelizeWithInvalidCredentials = new Sequelize("omg", "bar", null, _.omit(this.sequelize.options, ['host']))
var User2 = this.sequelizeWithInvalidCredentials.define('User', { name: DataTypes.STRING, bio: DataTypes.TEXT }) var User2 = this.sequelizeWithInvalidCredentials.define('User', { name: DataTypes.STRING, bio: DataTypes.TEXT })
User2.sync().error(function(err) { User2.sync().error(function(err) {
if (dialect === "postgres" || dialect === "postgres-native") { if (dialect === "postgres" || dialect === "postgres-native") {
assert([ assert([
'fe_sendauth: no password supplied',
'role "bar" does not exist', 'role "bar" does not exist',
'FATAL: role "bar" does not exist', 'FATAL: role "bar" does not exist',
'password authentication failed for user "bar"' 'password authentication failed for user "bar"'
...@@ -415,6 +416,20 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -415,6 +416,20 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
done() done()
}) })
}) })
it('fails with incorrect database credentials (2)', function (done) {
var sequelize = new Sequelize('db', 'user', 'pass', {
dialect: this.sequelize.options.dialect
});
var Project = sequelize.define('Project', {title: Sequelize.STRING})
var Task = sequelize.define('Task', {title: Sequelize.STRING})
sequelize.sync({force: true}).done(function (err) {
expect(err).to.be.ok
done()
})
})
} }
describe("doesn't emit logging when explicitly saying not to", function() { describe("doesn't emit logging when explicitly saying not to", function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!