From 2fec24dff640f291a72edc80978ef9790b41fd58 Mon Sep 17 00:00:00 2001 From: 2kindsofcs <2kindsofcs@gmail.com> Date: Sat, 19 Oct 2019 17:01:58 +0900 Subject: [PATCH 1/3] fix: fix type of methods in query-interface --- types/lib/query-interface.d.ts | 35 +++++++++++++++++++++------------- types/test/query-interface.ts | 2 ++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/types/lib/query-interface.d.ts b/types/lib/query-interface.d.ts index b53b377472fa..2da8243f44a2 100644 --- a/types/lib/query-interface.d.ts +++ b/types/lib/query-interface.d.ts @@ -120,6 +120,15 @@ export interface QueryInterfaceDropAllTablesOptions extends QueryInterfaceOption skip?: string[]; } +export interface TablenameWithSchema { + tableName: string; + schema?: string; + delimiter?: string; + as?: string; + name?: string; +} +export type Tablename = string | TablenameWithSchema; + export type IndexType = 'UNIQUE' | 'FULLTEXT' | 'SPATIAL'; export type IndexMethod = 'BTREE' | 'HASH' | 'GIST' | 'SPGIST' | 'GIN' | 'BRIN' | string; @@ -436,7 +445,7 @@ export class QueryInterface { * Inserts or Updates a record in the database */ public upsert( - tableName: string, + tableName: Tablename, values: object, updateValues: object, model: typeof Model, @@ -447,7 +456,7 @@ export class QueryInterface { * Inserts multiple records at once */ public bulkInsert( - tableName: string, + tableName: Tablename, records: object[], options?: QueryOptions, attributes?: string[] | string @@ -458,7 +467,7 @@ export class QueryInterface { */ public update( instance: Model, - tableName: string, + tableName: Tablename, values: object, identifier: WhereOptions, options?: QueryOptions @@ -468,7 +477,7 @@ export class QueryInterface { * Updates multiple rows at once */ public bulkUpdate( - tableName: string, + tableName: Tablename, values: object, identifier: WhereOptions, options?: QueryOptions, @@ -478,13 +487,13 @@ export class QueryInterface { /** * Deletes a row */ - public delete(instance: Model | null, tableName: string, identifier: WhereOptions, options?: QueryOptions): Promise; + public delete(instance: Model | null, tableName: Tablename, identifier: WhereOptions, options?: QueryOptions): Promise; /** * Deletes multiple rows at once */ public bulkDelete( - tableName: string, + tableName: Tablename, identifier: WhereOptions, options?: QueryOptions, model?: typeof Model @@ -493,14 +502,14 @@ export class QueryInterface { /** * Returns selected rows */ - public select(model: typeof Model | null, tableName: string, options?: QueryOptionsWithWhere): Promise; + public select(model: typeof Model | null, tableName: Tablename, options?: QueryOptionsWithWhere): Promise; /** * Increments a row value */ public increment( instance: Model, - tableName: string, + tableName: Tablename, values: object, identifier: WhereOptions, options?: QueryOptions @@ -510,7 +519,7 @@ export class QueryInterface { * Selects raw without parsing the string into an object */ public rawSelect( - tableName: string, + tableName: Tablename, options: QueryOptionsWithWhere, attributeSelector: string | string[], model?: typeof Model @@ -521,7 +530,7 @@ export class QueryInterface { * parameters. */ public createTrigger( - tableName: string, + tableName: Tablename, triggerName: string, timingType: string, fireOnArray: { @@ -536,13 +545,13 @@ export class QueryInterface { /** * Postgres only. Drops the specified trigger. */ - public dropTrigger(tableName: string, triggerName: string, options?: QueryInterfaceOptions): Promise; + public dropTrigger(tableName: Tablename, triggerName: string, options?: QueryInterfaceOptions): Promise; /** * Postgres only. Renames a trigger */ public renameTrigger( - tableName: string, + tableName: Tablename, oldTriggerName: string, newTriggerName: string, options?: QueryInterfaceOptions @@ -585,7 +594,7 @@ export class QueryInterface { /** * Escape a table name */ - public quoteTable(identifier: string): string; + public quoteTable(identifier: Tablename): string; /** * Split an identifier into .-separated tokens and quote each part. If force is true, the identifier will be diff --git a/types/test/query-interface.ts b/types/test/query-interface.ts index dd5956e9bb1c..d5592da4ecb3 100644 --- a/types/test/query-interface.ts +++ b/types/test/query-interface.ts @@ -51,6 +51,8 @@ queryInterface.createTable( queryInterface.dropTable('nameOfTheExistingTable'); +queryInterface.bulkDelete({ tableName: 'foo', schema: 'bar' }, {}, {}); + queryInterface.dropAllTables(); queryInterface.renameTable('Person', 'User'); From e72dc367408a8f54be25a408135f6bbb34c817b7 Mon Sep 17 00:00:00 2001 From: 2kindsofcs <2kindsofcs@gmail.com> Date: Sun, 20 Oct 2019 20:38:28 +0900 Subject: [PATCH 2/3] test: add more tests regarding type Tablename --- types/test/query-interface.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/test/query-interface.ts b/types/test/query-interface.ts index d5592da4ecb3..ced3c475af04 100644 --- a/types/test/query-interface.ts +++ b/types/test/query-interface.ts @@ -53,6 +53,14 @@ queryInterface.dropTable('nameOfTheExistingTable'); queryInterface.bulkDelete({ tableName: 'foo', schema: 'bar' }, {}, {}); +queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {}); + +queryInterface.bulkUpdate({ tableName: 'foo', delimiter: 'bar', as: 'baz', name: 'quz' }, {}, {}); + +queryInterface.dropTrigger({ tableName: 'foo', as: 'bar', name: 'baz' }, 'foo', {}); + +queryInterface.quoteTable({ tableName: 'foo', delimiter: 'bar' }); + queryInterface.dropAllTables(); queryInterface.renameTable('Person', 'User'); From 22d6a6216160d252c19f199aad2ff2f0ef3f86e8 Mon Sep 17 00:00:00 2001 From: 2kindsofcs <2kindsofcs@gmail.com> Date: Tue, 22 Oct 2019 19:57:50 +0900 Subject: [PATCH 3/3] style: use camel case --- types/lib/query-interface.d.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/types/lib/query-interface.d.ts b/types/lib/query-interface.d.ts index 2da8243f44a2..7a26ae2ef422 100644 --- a/types/lib/query-interface.d.ts +++ b/types/lib/query-interface.d.ts @@ -120,14 +120,14 @@ export interface QueryInterfaceDropAllTablesOptions extends QueryInterfaceOption skip?: string[]; } -export interface TablenameWithSchema { +export interface TableNameWithSchema { tableName: string; schema?: string; delimiter?: string; as?: string; name?: string; } -export type Tablename = string | TablenameWithSchema; +export type TableName = string | TableNameWithSchema; export type IndexType = 'UNIQUE' | 'FULLTEXT' | 'SPATIAL'; export type IndexMethod = 'BTREE' | 'HASH' | 'GIST' | 'SPGIST' | 'GIN' | 'BRIN' | string; @@ -445,7 +445,7 @@ export class QueryInterface { * Inserts or Updates a record in the database */ public upsert( - tableName: Tablename, + tableName: TableName, values: object, updateValues: object, model: typeof Model, @@ -456,7 +456,7 @@ export class QueryInterface { * Inserts multiple records at once */ public bulkInsert( - tableName: Tablename, + tableName: TableName, records: object[], options?: QueryOptions, attributes?: string[] | string @@ -467,7 +467,7 @@ export class QueryInterface { */ public update( instance: Model, - tableName: Tablename, + tableName: TableName, values: object, identifier: WhereOptions, options?: QueryOptions @@ -477,7 +477,7 @@ export class QueryInterface { * Updates multiple rows at once */ public bulkUpdate( - tableName: Tablename, + tableName: TableName, values: object, identifier: WhereOptions, options?: QueryOptions, @@ -487,13 +487,13 @@ export class QueryInterface { /** * Deletes a row */ - public delete(instance: Model | null, tableName: Tablename, identifier: WhereOptions, options?: QueryOptions): Promise; + public delete(instance: Model | null, tableName: TableName, identifier: WhereOptions, options?: QueryOptions): Promise; /** * Deletes multiple rows at once */ public bulkDelete( - tableName: Tablename, + tableName: TableName, identifier: WhereOptions, options?: QueryOptions, model?: typeof Model @@ -502,14 +502,14 @@ export class QueryInterface { /** * Returns selected rows */ - public select(model: typeof Model | null, tableName: Tablename, options?: QueryOptionsWithWhere): Promise; + public select(model: typeof Model | null, tableName: TableName, options?: QueryOptionsWithWhere): Promise; /** * Increments a row value */ public increment( instance: Model, - tableName: Tablename, + tableName: TableName, values: object, identifier: WhereOptions, options?: QueryOptions @@ -519,7 +519,7 @@ export class QueryInterface { * Selects raw without parsing the string into an object */ public rawSelect( - tableName: Tablename, + tableName: TableName, options: QueryOptionsWithWhere, attributeSelector: string | string[], model?: typeof Model @@ -530,7 +530,7 @@ export class QueryInterface { * parameters. */ public createTrigger( - tableName: Tablename, + tableName: TableName, triggerName: string, timingType: string, fireOnArray: { @@ -545,13 +545,13 @@ export class QueryInterface { /** * Postgres only. Drops the specified trigger. */ - public dropTrigger(tableName: Tablename, triggerName: string, options?: QueryInterfaceOptions): Promise; + public dropTrigger(tableName: TableName, triggerName: string, options?: QueryInterfaceOptions): Promise; /** * Postgres only. Renames a trigger */ public renameTrigger( - tableName: Tablename, + tableName: TableName, oldTriggerName: string, newTriggerName: string, options?: QueryInterfaceOptions @@ -594,7 +594,7 @@ export class QueryInterface { /** * Escape a table name */ - public quoteTable(identifier: Tablename): string; + public quoteTable(identifier: TableName): string; /** * Split an identifier into .-separated tokens and quote each part. If force is true, the identifier will be