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

Commit dc090b5c by Mick Hansen

Merge branch 'vickenstein-postgres-partial-index'

2 parents e7f3b195 1d22f404
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
- [BUG] instance.removeAssociation(s) do not fire the select query twice anymore - [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) - [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] 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. - [DEPRECATED] The query-chainer is deprecated and will be removed in version 2.2. Please use promises instead.
- [REMOVED] Events are no longer supported. - [REMOVED] Events are no longer supported.
......
...@@ -538,6 +538,10 @@ module.exports = (function() { ...@@ -538,6 +538,10 @@ module.exports = (function() {
delete options.type; delete options.type;
} }
if (options.where) {
options.where = this.whereQuery(options.where);
}
return Utils._.compact([ return Utils._.compact([
'CREATE', 'CREATE',
options.unique ? 'UNIQUE' : '', options.unique ? 'UNIQUE' : '',
...@@ -548,7 +552,8 @@ module.exports = (function() { ...@@ -548,7 +552,8 @@ module.exports = (function() {
'ON', this.quoteIdentifiers(tableName), 'ON', this.quoteIdentifiers(tableName),
this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '', this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '',
'(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')', '(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')',
(this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined) (this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined),
(this._dialect.supports.index.where && options.where ? options.where : undefined)
]).join(' '); ]).join(' ');
}, },
......
...@@ -37,6 +37,7 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp ...@@ -37,6 +37,7 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
index: { index: {
concurrently: true, concurrently: true,
using: 2, using: 2,
where: true
}, },
JSON: true, JSON: true,
JSONB: true JSONB: true
......
...@@ -55,6 +55,33 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -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) { if (current.dialect.supports.JSON) {
test('operator', function () { test('operator', function () {
expectsql(sql.addIndexQuery('table', { 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!