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

Commit 3d1ef1ee by Matt Broadstone

fix a few things missed in the "great cherry-pick"

1 parent 6e13407a
...@@ -1468,7 +1468,22 @@ module.exports = (function() { ...@@ -1468,7 +1468,22 @@ module.exports = (function() {
booleanValue: function(value) { booleanValue: function(value) {
return value; return value;
} },
uniqueConstraintMapping: {
code: 'EREQUEST',
map: function(str) {
// we're manually remvoving uniq_ here for a future capability of defining column names explicitly
var match = str.match(/Violation of UNIQUE KEY constraint '(.*)'. Cannot insert duplicate key in object '?(.*?)$/);
if (match === null || match.length < 2) {
return false;
}
return {
indexName: match[1],
fields: match[1].split('_')
};
}
},
}; };
/* istanbul ignore next */ /* istanbul ignore next */
......
...@@ -220,7 +220,7 @@ module.exports = (function() { ...@@ -220,7 +220,7 @@ module.exports = (function() {
}); });
}; };
AbstractQuery.prototype.handleInsertQuery = function(results, metaData) { Query.prototype.handleInsertQuery = function(results, metaData) {
if (this.callee) { if (this.callee) {
// add the inserted row id to the instance // add the inserted row id to the instance
var autoIncrementField = this.callee.Model.autoIncrementField var autoIncrementField = this.callee.Model.autoIncrementField
......
...@@ -354,9 +354,10 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -354,9 +354,10 @@ describe(Support.getTestDialectTeaser("Model"), function () {
} }
}); });
}); });
}) });
it('allows us to customize the error message for unique constraint', function() {
if(dialect !== 'mssql' ? it : it.skip)('allows us to customize the error message for unique constraint', function(done) {
var self = this var self = this
, User = this.sequelize.define('UserWithUniqueUsername', { , User = this.sequelize.define('UserWithUniqueUsername', {
username: { type: Sequelize.STRING, unique: { name: 'user_and_email', msg: 'User and email must be unique' }}, username: { type: Sequelize.STRING, unique: { name: 'user_and_email', msg: 'User and email must be unique' }},
......
...@@ -17,7 +17,7 @@ var chai = require('chai') ...@@ -17,7 +17,7 @@ var chai = require('chai')
chai.config.includeStack = true chai.config.includeStack = true
var qq = function(str) { var qq = function(str) {
if (dialect == 'postgres' || dialect == 'sqlite') { if (dialect == 'postgres' || dialect == 'sqlite' || dialect === 'mssql') {
return '"' + str + '"' return '"' + str + '"'
} else if (Support.dialectIsMySQL()) { } else if (Support.dialectIsMySQL()) {
return '`' + str + '`' return '`' + str + '`'
...@@ -108,7 +108,6 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -108,7 +108,6 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
it('triggers the actual adapter error', function(done) { it('triggers the actual adapter error', function(done) {
this this
.sequelizeWithInvalidConnection .sequelizeWithInvalidConnection
.authenticate() .authenticate()
...@@ -331,7 +330,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -331,7 +330,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
it('dot separated attributes when doing a raw query without nest', function(done) { it('dot separated attributes when doing a raw query without nest', function(done) {
var tickChar = (dialect === 'postgres') ? '"' : '`' var tickChar = (dialect === 'postgres' || dialect === 'mssql') ? '"' : '`'
, sql = "select 1 as " + Sequelize.Utils.addTicks('foo.bar.baz', tickChar) , sql = "select 1 as " + Sequelize.Utils.addTicks('foo.bar.baz', tickChar)
this.sequelize.query(sql, null, { raw: true, nest: false }).success(function(result) { this.sequelize.query(sql, null, { raw: true, nest: false }).success(function(result) {
...@@ -341,7 +340,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -341,7 +340,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
it('destructs dot separated attributes when doing a raw query using nest', function(done) { it('destructs dot separated attributes when doing a raw query using nest', function(done) {
var tickChar = (dialect === 'postgres') ? '"' : '`' var tickChar = (dialect === 'postgres' || dialect === 'mssql') ? '"' : '`'
, sql = "select 1 as " + Sequelize.Utils.addTicks('foo.bar.baz', tickChar) , sql = "select 1 as " + Sequelize.Utils.addTicks('foo.bar.baz', tickChar)
this.sequelize.query(sql, null, { raw: true, nest: true }).success(function(result) { this.sequelize.query(sql, null, { raw: true, nest: true }).success(function(result) {
...@@ -426,11 +425,16 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -426,11 +425,16 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
}) })
it('handles AS in conjunction with functions just fine', function(done) { it('handles AS in conjunction with functions just fine', function(done) {
this.sequelize.query('SELECT ' + (dialect === "sqlite" ? 'date(\'now\')' : 'NOW()') + ' AS t').success(function(result) { var datetime = (dialect === "sqlite" ? 'date(\'now\')' : 'NOW()');
if (dialect==="mssql") {
datetime = "GETDATE()"
}
this.sequelize.query('SELECT ' + datetime + ' AS t').success(function(result) {
expect(moment(result[0].t).isValid()).to.be.true expect(moment(result[0].t).isValid()).to.be.true
done() done()
}) });
}) });
if (Support.getTestDialect() === 'postgres') { if (Support.getTestDialect() === 'postgres') {
it('replaces named parameters with the passed object and ignores casts', function(done) { it('replaces named parameters with the passed object and ignores casts', function(done) {
...@@ -619,7 +623,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -619,7 +623,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
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().done(function(err) {
if (dialect === "postgres" || dialect === "postgres-native") { if (dialect === "postgres" || dialect === "postgres-native") {
assert([ assert([
'fe_sendauth: no password supplied', 'fe_sendauth: no password supplied',
...@@ -627,9 +631,12 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () { ...@@ -627,9 +631,12 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
'FATAL: role "bar" does not exist', 'FATAL: role "bar" does not exist',
'password authentication failed for user "bar"' 'password authentication failed for user "bar"'
].indexOf(err.message.trim()) !== -1) ].indexOf(err.message.trim()) !== -1)
} else if (dialect === 'mssql') {
expect(err.message).to.match(/.*ECONNREFUSED.*/);
} else { } else {
expect(err.message.toString()).to.match(/.*Access\ denied.*/) expect(err.message.toString()).to.match(/.*Access\ denied.*/);
} }
done() done()
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!