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

Commit 4bbd0aab by Michael Schonfeld

throw error for psql, and test for it

1 parent 52f5e51e
......@@ -267,7 +267,11 @@ module.exports = (function() {
})
},
bulkInsertQuery: function(tableName, attrValueHashes) {
bulkInsertQuery: function(tableName, attrValueHashes, options) {
if(options && options.ignoreDuplicates) {
throw new Error("Postgres does not support the 'ignoreDuplicates' option.")
}
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %> RETURNING *;"
, tuples = []
, serials = []
......
......@@ -991,27 +991,43 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it("should support the insert ignoreDuplicates option", function(done) {
var self = this
, data = [{ uniqueName: 'Peter', secretValue: '42' },
{ uniqueName: 'Paul', secretValue: '23' }]
this.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'] }).success(function() {
data.push({ uniqueName: 'Michael', secretValue: '26' });
self.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'], ignoreDuplicates: true }).success(function() {
self.User.findAll({order: 'id'}).success(function(users) {
expect(users.length).to.equal(3)
expect(users[0].uniqueName).to.equal("Peter")
expect(users[0].secretValue).to.equal("42");
expect(users[1].uniqueName).to.equal("Paul")
expect(users[1].secretValue).to.equal("23");
expect(users[2].uniqueName).to.equal("Michael")
expect(users[2].secretValue).to.equal("26");
if (Support.getTestDialect() !== 'postgres') {
it("should support the ignoreDuplicates option", function(done) {
var self = this
, data = [{ uniqueName: 'Peter', secretValue: '42' },
{ uniqueName: 'Paul', secretValue: '23' }]
this.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'] }).success(function() {
data.push({ uniqueName: 'Michael', secretValue: '26' });
self.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'], ignoreDuplicates: true }).success(function() {
self.User.findAll({order: 'id'}).success(function(users) {
expect(users.length).to.equal(3)
expect(users[0].uniqueName).to.equal("Peter")
expect(users[0].secretValue).to.equal("42");
expect(users[1].uniqueName).to.equal("Paul")
expect(users[1].secretValue).to.equal("23");
expect(users[2].uniqueName).to.equal("Michael")
expect(users[2].secretValue).to.equal("26");
done()
});
});
})
})
} else {
it("should throw an error when the ignoreDuplicates option is passed", function(done) {
var self = this
, data = [{ uniqueName: 'Peter', secretValue: '42' },
{ uniqueName: 'Paul', secretValue: '23' }]
this.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'] }).success(function() {
data.push({ uniqueName: 'Michael', secretValue: '26' });
self.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'], ignoreDuplicates: true }).success(function() {
expect(err.message).to.match(/Postgres does not support the 'ignoreDuplicates' option./);
done()
});
});
})
})
})
}
describe('enums', function() {
it('correctly restores enum values', function(done) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!