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

Commit c5f12531 by Mick Hansen

Merge pull request #2437 from nrmitchi/issue/postgresArrays

Issue/postgres arrays
2 parents 7c5cb57b dc2cb90f
Showing with 27 additions and 1 deletions
...@@ -112,7 +112,13 @@ SqlString.arrayToList = function(array, timeZone, dialect, field) { ...@@ -112,7 +112,13 @@ SqlString.arrayToList = function(array, timeZone, dialect, field) {
} }
var ret = 'ARRAY[' + valstr + ']'; var ret = 'ARRAY[' + valstr + ']';
if (!!field && !!field.type) { if (!!field && !!field.type) {
ret += '::' + field.type.replace(/\(\d+\)/g, ''); // Need to translate DATETIME to TIMESTAMP WITH TIME ZONE for Postgres here
// There has to be a better solution than this
if (dialect === "postgres") {
ret += '::' + field.type.replace(/\(\d+\)/g, '').replace(/DATETIME/, 'TIMESTAMP WITH TIME ZONE');
} else {
ret += '::' + field.type.replace(/\(\d+\)/g, '');
}
} }
return ret; return ret;
} else { } else {
......
...@@ -370,6 +370,26 @@ if (dialect.match(/^postgres/)) { ...@@ -370,6 +370,26 @@ if (dialect.match(/^postgres/)) {
}) })
}) })
describe('timestamps', function () {
beforeEach( function (done) {
this.User = this.sequelize.define('User', {
dates : DataTypes.ARRAY(DataTypes.DATE)
})
this.User.sync({ force: true }).success(function() {
done()
})
})
it('should use postgres "TIMESTAMP WITH TIME ZONE" instead of "DATETIME"', function (done) {
this.User.create({
dates: []
}).on('sql', function(sql) {
expect(sql.indexOf('TIMESTAMP WITH TIME ZONE')).to.be.greaterThan(0)
done()
})
})
})
describe('model', function() { describe('model', function() {
it("create handles array correctly", function(done) { it("create handles array correctly", function(done) {
this.User this.User
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!