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

Commit 839f1a97 by SuHun Han Committed by GitHub

fix(query-interface): allow sequelize.fn and sequelize.literal in fields of IndexesOptions (#12224)

1 parent 2fa578ea
......@@ -4,6 +4,7 @@ import QueryTypes = require('./query-types');
import { Sequelize, RetryOptions } from './sequelize';
import { Transaction } from './transaction';
import { SetRequired } from './../type-helpers/set-required';
import { Fn, Literal } from './utils';
type BindOrReplacements = { [key: string]: unknown } | unknown[];
type FieldMap = { [key: string]: string };
......@@ -172,7 +173,7 @@ export interface IndexesOptions {
* (field name), `length` (create a prefix index of length chars), `order` (the direction the column
* should be sorted in), `collate` (the collation (sort order) for the column), `operator` (likes IndexesOptions['operator'])
*/
fields?: (string | { name: string; length?: number; order?: 'ASC' | 'DESC'; collate?: string; operator?: string })[];
fields?: (string | { name: string; length?: number; order?: 'ASC' | 'DESC'; collate?: string; operator?: string } | Fn | Literal)[];
/**
* The method to create the index by (`USING` statement in SQL). BTREE and HASH are supported by mysql and
......
import { DataTypes, Model } from 'sequelize';
import { DataTypes, Model, fn, literal, col } from 'sequelize';
// tslint:disable-next-line:no-submodule-imports
import { QueryInterface } from 'sequelize/lib/query-interface';
......@@ -154,6 +154,20 @@ queryInterface.addIndex('Foo', {
],
});
queryInterface.addIndex('Foo', {
name: 'foo_b_lower',
fields: [
fn('lower', col('foo_b'))
],
});
queryInterface.addIndex('Foo', {
name: 'foo_c_lower',
fields: [
literal('LOWER(foo_c)')
]
})
queryInterface.removeIndex('Person', 'SuperDuperIndex');
// or
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!