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

Commit 64960b02 by Jan Aagaard Meier

Change the default when searching postgres arrays from && to =

1 parent 930cb9a5
...@@ -7,11 +7,13 @@ ...@@ -7,11 +7,13 @@
- [BUG] Customized error message can now be set for unique constraint that was created manually (not with sync, but e.g. with migrations) or that has fields with underscore naming. This was problem at least with postgres before. - [BUG] Customized error message can now be set for unique constraint that was created manually (not with sync, but e.g. with migrations) or that has fields with underscore naming. This was problem at least with postgres before.
- [BUG] Fixed a bug where plain objects like `{ in: [...] }` were not properly converted to SQL when combined with a sequelize method (`fn`, `where` etc.). Closes [#2077](https://github.com/sequelize/sequelize/issues/2077) - [BUG] Fixed a bug where plain objects like `{ in: [...] }` were not properly converted to SQL when combined with a sequelize method (`fn`, `where` etc.). Closes [#2077](https://github.com/sequelize/sequelize/issues/2077)
- [INTERNALS] Update `inflection` dependency to v1.5.2 - [INTERNALS] Update `inflection` dependency to v1.5.2
- [BUG] Made the default for array search in postgres exact comparison instead of overlap
#### Backwards compatability changes #### Backwards compatability changes
- When eager-loading a many-to-many association, the attributes of the through table are now accessible through an attribute named after the through model rather than the through table name singularized. i.e. `Task.find({include: Worker})` where the table name for through model `TaskWorker` is `TableTaskWorkers` used to produce `{ Worker: { ..., TableTaskWorker: {...} } }`. It now produces `{ Worker: { ..., TaskWorker: {...} } }`. Does not affect models where table name is auto-defined by Sequelize, or where table name is model name pluralized. - When eager-loading a many-to-many association, the attributes of the through table are now accessible through an attribute named after the through model rather than the through table name singularized. i.e. `Task.find({include: Worker})` where the table name for through model `TaskWorker` is `TableTaskWorkers` used to produce `{ Worker: { ..., TableTaskWorker: {...} } }`. It now produces `{ Worker: { ..., TaskWorker: {...} } }`. Does not affect models where table name is auto-defined by Sequelize, or where table name is model name pluralized.
- When using `Model#find()` with an `order` clause, the table name is prepended to the `ORDER BY` SQL. e.g. `ORDER BY Task.id` rather than `ORDER BY id`. The change is to avoid ambiguous column names where there are eager-loaded associations with the same column names. A side effect is that code like `Task.findAll( { include: [ User ], order: [ [ 'Users.id', 'ASC' ] ] } )` will now throw an error. This should be achieved with `Task.findAll( { include: [ User ], order: [ [ User, 'id', 'ASC' ] ] } )` instead. - When using `Model#find()` with an `order` clause, the table name is prepended to the `ORDER BY` SQL. e.g. `ORDER BY Task.id` rather than `ORDER BY id`. The change is to avoid ambiguous column names where there are eager-loaded associations with the same column names. A side effect is that code like `Task.findAll( { include: [ User ], order: [ [ 'Users.id', 'ASC' ] ] } )` will now throw an error. This should be achieved with `Task.findAll( { include: [ User ], order: [ [ User, 'id', 'ASC' ] ] } )` instead.
- Nested HSTORE objects are no longer supported. Use DataTypes.JSON instead. - Nested HSTORE objects are no longer supported. Use DataTypes.JSON instead.
- In PG `where: { arr: [1, 2] }` where the `arr` column is an array will now use strict comparison (`=`) instead of the overlap operator (`&&`). To obtain the old behaviour, use ` where: { arr: { overlap: [1, 2] }}`
# 2.0.0-rc2 # 2.0.0-rc2
- [FEATURE] Added to posibility of using a sequelize object as key in `sequelize.where`. Also added the option of specifying a comparator - [FEATURE] Added to posibility of using a sequelize object as key in `sequelize.where`. Also added the option of specifying a comparator
......
...@@ -703,7 +703,13 @@ Project.findAll({ ...@@ -703,7 +703,13 @@ Project.findAll({
lte: 10, // id lte: 10, // id
ne: 20, // id != 20 ne: 20, // id != 20
between: [6, 10], // BETWEEN 6 AND 10 between: [6, 10], // BETWEEN 6 AND 10
nbetween: [11, 15] // NOT BETWEEN 11 AND 15 nbetween: [11, 15], // NOT BETWEEN 11 AND 15
in: [1, 2], // IN [1, 2]
like: '%hat', // LIKE '%hat'
nlike: '%hat' // NOT LIKE '%hat'
ilike: '%hat' // ILIKE '%hat' (case insensitive)
nilike: '%hat' // NOT ILIKE '%hat'
overlap: [1, 2] // && [1, 2] (PG array overlap operator)
} }
} }
}) })
......
...@@ -1682,15 +1682,15 @@ module.exports = (function() { ...@@ -1682,15 +1682,15 @@ module.exports = (function() {
} else { } else {
for (var logic in value) { for (var logic in value) {
var logicResult = Utils.getWhereLogic(logic, value[logic]); var logicResult = Utils.getWhereLogic(logic, value[logic]);
if (logicResult === 'IN' || logicResult === 'NOT IN') {
var values = Array.isArray(value[logic]) ? value[logic] : [value[logic]]; if (logicResult === 'BETWEEN' || logicResult === 'NOT BETWEEN') {
result.push(this.arrayValue(values, key, _key, dao, logicResult));
}
else if (logicResult === 'BETWEEN' || logicResult === 'NOT BETWEEN') {
_value = this.escape(value[logic][0]); _value = this.escape(value[logic][0]);
var _value2 = this.escape(value[logic][1]); var _value2 = this.escape(value[logic][1]);
result.push(' (' + _key + ' ' + logicResult + ' ' + _value + ' AND ' + _value2 + ') '); result.push(' (' + _key + ' ' + logicResult + ' ' + _value + ' AND ' + _value2 + ') ');
} else if (logicResult === 'IN' || logicResult === 'NOT IN' || Array.isArray(value[logic])) {
var values = Array.isArray(value[logic]) ? value[logic] : [value[logic]];
result.push(this.arrayValue(values, key, _key, dao, logicResult));
} else { } else {
_value = this.escape(value[logic]); _value = this.escape(value[logic]);
result.push([_key, _value].join(' ' + logicResult + ' ')); result.push([_key, _value].join(' ' + logicResult + ' '));
......
...@@ -221,7 +221,11 @@ module.exports = (function() { ...@@ -221,7 +221,11 @@ module.exports = (function() {
if (col && ((!!coltype && coltype.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null))) { if (col && ((!!coltype && coltype.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null))) {
_value = 'ARRAY[' + value.map(this.escape.bind(this)).join(',') + ']::' + (!!col.type ? col.type : col.toString()); _value = 'ARRAY[' + value.map(this.escape.bind(this)).join(',') + ']::' + (!!col.type ? col.type : col.toString());
return [_key, _value].join(' && ');
if (logicResult === 'IN') {
logicResult = '=';
}
return [_key, _value].join(' ' + logicResult + ' ');
} else { } else {
_value = '(' + value.map(this.escape.bind(this)).join(',') + ')'; _value = '(' + value.map(this.escape.bind(this)).join(',') + ')';
return [_key, _value].join(' ' + logicResult + ' '); return [_key, _value].join(' ' + logicResult + ' ');
......
...@@ -352,6 +352,8 @@ var Utils = module.exports = { ...@@ -352,6 +352,8 @@ var Utils = module.exports = {
case 'nilike': case 'nilike':
case 'notilike': case 'notilike':
return 'NOT ILIKE'; return 'NOT ILIKE';
case 'overlap':
return '&&';
default: default:
return ''; return '';
} }
......
...@@ -33,7 +33,7 @@ if (dialect.match(/^postgres/)) { ...@@ -33,7 +33,7 @@ if (dialect.match(/^postgres/)) {
it('should be able to search within an array', function(done) { it('should be able to search within an array', function(done) {
this.User.all({where: {email: ['hello', 'world']}}).on('sql', function(sql) { this.User.all({where: {email: ['hello', 'world']}}).on('sql', function(sql) {
expect(sql).to.equal('SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."email" && ARRAY[\'hello\',\'world\']::TEXT[];') expect(sql).to.equal('SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];')
done() done()
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!