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

Commit 52916fb8 by Jan Aagaard Meier

Merge pull request #3041 from seegno-forks/enhancement/upgrade-pg-and-pg-native

Add support for postgres on io.js
2 parents ea30ef61 dd4fc8ec
......@@ -95,7 +95,7 @@ ConnectionManager.prototype.connect = function(config) {
}).tap(function (connection) {
if (self.sequelize.config.keepDefaultTimezone) return;
return new Promise(function (resolve, reject) {
connection.query("SET TIME ZONE INTERVAL '" + self.sequelize.options.timezone + "' HOUR TO MINUTE").on('error', function (err) {
connection.query("SET client_min_messages TO warning; SET TIME ZONE INTERVAL '" + self.sequelize.options.timezone + "' HOUR TO MINUTE").on('error', function (err) {
reject(err);
}).on('end', function () {
resolve();
......
......@@ -207,7 +207,7 @@ module.exports = (function() {
return results;
} else if (QueryTypes.BULKUPDATE === self.options.type) {
if (!self.options.returning) {
return result.rowCount;
return parseInt(result.rowCount, 10);
}
if (!!self.callee && !!self.callee._hasHstoreAttributes) {
......@@ -218,7 +218,7 @@ module.exports = (function() {
return self.handleSelectQuery(rows);
} else if (QueryTypes.BULKDELETE === self.options.type) {
return result.rowCount;
return parseInt(result.rowCount, 10);
} else if (self.isUpsertQuery()) {
return rows[0].sequelize_upsert;
} else if (self.isInsertQuery() || self.isUpdateQuery()) {
......@@ -256,10 +256,14 @@ module.exports = (function() {
, table
, index;
switch (err.code) {
var code = err.code || err.sqlState
, errMessage = err.message || err.messagePrimary
, errDetail = err.detail || err.messageDetail;
switch (code) {
case '23503':
index = err.message.match(/violates foreign key constraint \"(.+?)\"/)[1];
table = err.message.match(/on table \"(.+?)\"/)[1];
index = errMessage.match(/violates foreign key constraint \"(.+?)\"/)[1];
table = errMessage.match(/on table \"(.+?)\"/)[1];
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
......@@ -270,7 +274,7 @@ module.exports = (function() {
case '23505':
// there are multiple different formats of error messages for this error code
// this regex should check at least two
match = err.detail.match(/Key \((.*?)\)=\((.*?)\)/);
match = errDetail.match(/Key \((.*?)\)=\((.*?)\)/);
if (match) {
var fields = Utils._.zipObject(match[1].split(', '), match[2].split(', '))
......@@ -299,7 +303,7 @@ module.exports = (function() {
});
} else {
return new sequelizeErrors.UniqueConstraintError({
message: err.message,
message: errMessage,
parent: err
});
}
......
......@@ -47,7 +47,8 @@
"chai-as-promised": "^4.1.1",
"sqlite3": "~3.0.0",
"mysql": "~2.5.0",
"pg": "~3.6.0",
"pg": "^4.2.0",
"pg-native": "^1.8.0",
"pg-hstore": "^2.3.1",
"tedious": "^1.7.0",
"watchr": "~2.4.11",
......
......@@ -22,7 +22,7 @@ describe(Support.getTestDialectTeaser('Configuration'), function() {
if (dialect === 'sqlite') {
// SQLite doesn't have a breakdown of error codes, so we are unable to discern between the different types of errors.
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.ConnectionError, 'SQLITE_CANTOPEN: unable to open database file');
} else if (dialect === 'mssql') {
} else if (dialect === 'mssql' || dialect === 'postgres') {
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith([seq.HostNotReachableError, seq.InvalidConnectionError]);
} else {
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.InvalidConnectionError, 'connect EINVAL');
......
......@@ -999,8 +999,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
{ username: 'Paul', secretValue: '42' },
{ username: 'Bob', secretValue: '43' }];
this.clock = sinon.useFakeTimers();
return this.User.bulkCreate(data).bind(this).then(function() {
return this.User.findAll({order: 'id'});
}).then(function(users) {
......@@ -1010,9 +1008,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(this.updatedAt).to.equalTime(users[2].updatedAt); // All users should have the same updatedAt
// Pass the time so we can actually see a change
this.clock.tick(1000);
return this.User.update({username: 'Bill'}, {where: {secretValue: '42'}});
return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.update({username: 'Bill'}, {where: {secretValue: '42'}});
});
}).then(function() {
return this.User.findAll({order: 'id'});
}).then(function(users) {
......@@ -1022,8 +1020,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(users[0].updatedAt).to.be.afterTime(this.updatedAt);
expect(users[2].updatedAt).to.equalTime(this.updatedAt);
this.clock.restore();
});
});
......
......@@ -99,7 +99,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
username: 'gottlieb'
}
}).then(function () {
throw new Error('I should have ben rejected');
throw new Error('I should have been rejected');
}, function (err) {
expect(err instanceof Sequelize.UniqueConstraintError).to.be.ok;
expect(err.fields).to.be.ok;
......
......@@ -18,8 +18,6 @@ chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('Model'), function() {
beforeEach(function() {
this.clock = sinon.useFakeTimers();
this.User = this.sequelize.define('user', {
username: DataTypes.STRING,
foo: {
......@@ -35,10 +33,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return this.sequelize.sync({ force: true });
});
afterEach(function() {
this.clock.restore();
});
if (current.dialect.supports.upserts) {
describe('upsert', function() {
it('works with upsert on id', function() {
......@@ -49,8 +43,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(created).to.be.ok;
}
this.clock.tick(2000); // Make sure to pass some time so updatedAt != createdAt
return this.User.upsert({ id: 42, username: 'doe' });
return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.upsert({ id: 42, username: 'doe' });
});
}).then(function(created) {
if (dialect === 'sqlite') {
expect(created).not.to.be.defined;
......@@ -74,8 +69,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(created).to.be.ok;
}
this.clock.tick(2000); // Make sure to pass some time so updatedAt != createdAt
return this.User.upsert({ foo: 'baz', bar: 19, username: 'doe' });
return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.upsert({ foo: 'baz', bar: 19, username: 'doe' });
});
}).then(function(created) {
if (dialect === 'sqlite') {
expect(created).not.to.be.defined;
......
......@@ -119,7 +119,8 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
} else if (dialect === 'postgres') {
expect(
err.message.match(/connect ECONNREFUSED/) ||
err.message.match(/invalid port number/)
err.message.match(/invalid port number/) ||
err.message.match(/RangeError: Port should be > 0 and < 65536/)
).to.be.ok;
} else if (dialect === 'mssql') {
expect(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!