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

Commit 1d22f404 by Mick Hansen

feat(index): tests and new where query generator for postgres partial indexes

1 parent cce7a311
......@@ -3,6 +3,7 @@
- [BUG] instance.removeAssociation(s) do not fire the select query twice anymore
- [BUG] Error messages thrown by the db in languages other than english do not crash the app anymore (mysql, mariadb and postgres only) [#3567](https://github.com/sequelize/sequelize/pull/3567)
- [FEATURE] All querys can be logged individually by inserting `logging: fn` in the query option.
- [FEATURE] Partial index support for Postgres with `index.where`
- [DEPRECATED] The query-chainer is deprecated and will be removed in version 2.2. Please use promises instead.
- [REMOVED] Events are no longer supported.
......
......@@ -539,11 +539,7 @@ module.exports = (function() {
}
if (options.where) {
if (Array.isArray(options.where)) {
options.where = Utils.format(options.where);
} else if (!Utils._.isString(options.where)) {
delete options.where
}
options.where = this.whereQuery(options.where);
}
return Utils._.compact([
......@@ -557,7 +553,7 @@ module.exports = (function() {
this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '',
'(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')',
(this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined),
(this._dialect.supports.index.where && options.where ? 'WHERE ' + options.where : undefined)
(this._dialect.supports.index.where && options.where ? options.where : undefined)
]).join(' ');
},
......
......@@ -55,6 +55,33 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
});
}
if (current.dialect.supports.index.using === 2) {
test('WHERE', function () {
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: 'public'
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE "type" = \'public\''
});
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: {
$or: [
'group',
'private'
]
}
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE ("type" = \'group\' OR "type" = \'private\')'
});
});
}
if (current.dialect.supports.JSON) {
test('operator', function () {
expectsql(sql.addIndexQuery('table', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!