From d0315e8d62c961f3e5a9b24eb1724fb9a8d477e1 Mon Sep 17 00:00:00 2001 From: Sebastien Bramille Date: Mon, 21 Aug 2017 13:55:58 +0100 Subject: [PATCH] [Sequelize] Fix addIndex typing --- types/sequelize/index.d.ts | 35 +++++++++++++++++++++++++++++- types/sequelize/sequelize-tests.ts | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index 7524162a1b..dde51a4b96 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -5,6 +5,7 @@ // Ivan Drinchev // Brendan Abolivier // Patsakol Tangjitcharoenchai +// Sebastien Bramille // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -4175,7 +4176,7 @@ declare namespace sequelize { /** * Adds a new index to a table */ - addIndex(tableName: string | Object, attributes: string[], options?: QueryOptions, + addIndex(tableName: string | Object, attributes: string[], options?: DefineIndexOptions, rawTablename?: string): Promise; /** @@ -4825,6 +4826,38 @@ declare namespace sequelize { } + interface DefineIndexOptions { + /** + * The index type + */ + indicesType?: 'UNIQUE' | 'FULLTEXT' | 'SPATIAL'; + + /** + * The name of the index. Default is __ + */ + indexName?: string; + + /** + * For FULLTEXT columns set your parser + */ + parser?: string; + + /** + * Set a type for the index, e.g. BTREE. See the documentation of the used dialect + */ + indexType?: string; + + /** + * A function that receives the sql query, e.g. console.log + */ + logging?: Function; + + /** + * A hash of attributes to limit your index(Filtered Indexes - MSSQL & PostgreSQL only) + */ + where?: AnyWhereOptions; + } + /** * Interface for indexes property in DefineOptions * diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index aa14079e9d..ad96aa4ffc 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -1091,6 +1091,7 @@ queryInterface.createTable( 'table', { name : { type : Sequelize.STRING } }, { s queryInterface.addIndex( { schema : 'a', tableName : 'c' }, ['d', 'e'], { logging : function() {} }, 'schema_table' ); queryInterface.showIndex( { schema : 'schema', tableName : 'table' }, { logging : function() {} } ); queryInterface.addIndex( 'Group', ['from'] ); +queryInterface.addIndex( 'Group', ['from'], { indexName: 'group_from' } ); queryInterface.describeTable( '_Users', { logging : function() {} } ); queryInterface.createTable( 's', { table_id : { type : Sequelize.INTEGER, primaryKey : true, autoIncrement : true } } ); /* NOTE https://github.com/DefinitelyTyped/DefinitelyTyped/pull/5590