Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix type of methods in query-interface #11582

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 22 additions & 13 deletions types/lib/query-interface.d.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -458,7 +467,7 @@ export class QueryInterface {
*/
public update(
instance: Model,
tableName: string,
tableName: TableName,
values: object,
identifier: WhereOptions,
options?: QueryOptions
Expand All @@ -468,7 +477,7 @@ export class QueryInterface {
* Updates multiple rows at once
*/
public bulkUpdate(
tableName: string,
tableName: TableName,
values: object,
identifier: WhereOptions,
options?: QueryOptions,
Expand All @@ -478,13 +487,13 @@ export class QueryInterface {
/**
* Deletes a row
*/
public delete(instance: Model | null, tableName: string, identifier: WhereOptions, options?: QueryOptions): Promise<object>;
public delete(instance: Model | null, tableName: TableName, identifier: WhereOptions, options?: QueryOptions): Promise<object>;

/**
* Deletes multiple rows at once
*/
public bulkDelete(
tableName: string,
tableName: TableName,
identifier: WhereOptions,
options?: QueryOptions,
model?: typeof Model
Expand All @@ -493,14 +502,14 @@ export class QueryInterface {
/**
* Returns selected rows
*/
public select(model: typeof Model | null, tableName: string, options?: QueryOptionsWithWhere): Promise<object[]>;
public select(model: typeof Model | null, tableName: TableName, options?: QueryOptionsWithWhere): Promise<object[]>;

/**
* Increments a row value
*/
public increment(
instance: Model,
tableName: string,
tableName: TableName,
values: object,
identifier: WhereOptions,
options?: QueryOptions
Expand All @@ -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
Expand All @@ -521,7 +530,7 @@ export class QueryInterface {
* parameters.
*/
public createTrigger(
tableName: string,
tableName: TableName,
triggerName: string,
timingType: string,
fireOnArray: {
Expand All @@ -536,13 +545,13 @@ export class QueryInterface {
/**
* Postgres only. Drops the specified trigger.
*/
public dropTrigger(tableName: string, triggerName: string, options?: QueryInterfaceOptions): Promise<void>;
public dropTrigger(tableName: TableName, triggerName: string, options?: QueryInterfaceOptions): Promise<void>;

/**
* Postgres only. Renames a trigger
*/
public renameTrigger(
tableName: string,
tableName: TableName,
oldTriggerName: string,
newTriggerName: string,
options?: QueryInterfaceOptions
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions types/test/query-interface.ts
Expand Up @@ -51,6 +51,16 @@ queryInterface.createTable(

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');
Expand Down