From f3cab21eb6672a784a273ce57bef5824f68cab21 Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Sun, 17 Dec 2017 17:08:47 +0100 Subject: [PATCH 1/2] fix(types): add collate and constraints to query interface --- lib/query-interface.d.ts | 50 +++++++++++++++++++++++++++++++++++++++- test/query-interface.ts | 8 +++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/query-interface.d.ts b/lib/query-interface.d.ts index 9775197..d3cf84f 100644 --- a/lib/query-interface.d.ts +++ b/lib/query-interface.d.ts @@ -6,7 +6,8 @@ import { ModelAttributeColumnOptions, Model, Logging, - Transactionable + Transactionable, + WhereOptions } from './model'; import {Transaction} from './transaction'; import {DataType} from './data-types'; @@ -88,6 +89,7 @@ export interface QueryInterfaceOptions extends Logging, Transactionable {} export interface QueryInterfaceCreateTableOptions extends QueryInterfaceOptions { engine?: string; charset?: string; + collate?: string; /** * Used for compound unique keys. */ @@ -120,6 +122,42 @@ export interface QueryInterfaceIndexOptions extends QueryInterfaceOptions { indexType?: string; } +export interface AddUniqueConstraintOptions { + type: 'unique'; + name?: string; +} + +export interface AddDefaultConstraintOptions { + type: 'default'; + name?: string; + defaultValue?: any; +} + +export interface AddCheckConstraintOptions { + type: 'check'; + name?: string; + where?: WhereOptions; +} + +export interface AddPrimaryKeyConstraintOptions { + type: 'primary key'; + name?: string; +} + +export interface AddForeignKeyConstraintOptions { + type: 'foreign key'; + name?: string; + references?: { + table: string; + field: string; + }; + onDelete: string; + onUpdate: string; +} + +export type AddConstraintOptions = AddUniqueConstraintOptions | AddDefaultConstraintOptions | AddCheckConstraintOptions | AddPrimaryKeyConstraintOptions | AddForeignKeyConstraintOptions; + + /** * The interface that Sequelize uses to talk to all databases. * @@ -262,6 +300,16 @@ export class QueryInterface { removeIndex(tableName: string, attributes: string[], options?: QueryInterfaceIndexOptions): Promise; + /** + * Adds constraints to a table + */ + addConstraint(tableName: string, attributes: string[], options?: AddConstraintOptions | QueryInterfaceOptions): Promise; + + /** + * Removes constraints from a table + */ + removeConstraint(tableName: string, constraintName: string, options?: QueryInterfaceOptions): Promise; + /** * Shows the index of a table */ diff --git a/test/query-interface.ts b/test/query-interface.ts index d01943f..f18444a 100644 --- a/test/query-interface.ts +++ b/test/query-interface.ts @@ -37,6 +37,7 @@ queryInterface.createTable( }, { engine: 'MYISAM', // default: 'InnoDB' + collate: 'latin1_general_ci', charset: 'latin1' // default: null } ); @@ -152,3 +153,10 @@ queryInterface.removeIndex('Person', 'SuperDuperIndex'); // or queryInterface.removeIndex('Person', ['firstname', 'lastname']); + +queryInterface.addConstraint('Person', ['firstname', 'lastname'], { + type: 'unique', + name: 'firstnamexlastname' +}); + +queryInterface.removeConstraint('Person', 'firstnamexlastname'); From eef28582f3d4111dd3a991cbf7b083bba7fa2030 Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Sun, 17 Dec 2017 17:10:05 +0100 Subject: [PATCH 2/2] fixup! fix(types): add collate and constraints to query interface --- lib/query-interface.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/query-interface.d.ts b/lib/query-interface.d.ts index d3cf84f..aca029f 100644 --- a/lib/query-interface.d.ts +++ b/lib/query-interface.d.ts @@ -157,7 +157,6 @@ export interface AddForeignKeyConstraintOptions { export type AddConstraintOptions = AddUniqueConstraintOptions | AddDefaultConstraintOptions | AddCheckConstraintOptions | AddPrimaryKeyConstraintOptions | AddForeignKeyConstraintOptions; - /** * The interface that Sequelize uses to talk to all databases. *