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

Commit c77c553c by 2kindsofcs Committed by Sushant

fix(typings): query-interface table schema (#11582)

1 parent 7ffa3d40
...@@ -120,6 +120,15 @@ export interface QueryInterfaceDropAllTablesOptions extends QueryInterfaceOption ...@@ -120,6 +120,15 @@ export interface QueryInterfaceDropAllTablesOptions extends QueryInterfaceOption
skip?: string[]; 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 IndexType = 'UNIQUE' | 'FULLTEXT' | 'SPATIAL';
export type IndexMethod = 'BTREE' | 'HASH' | 'GIST' | 'SPGIST' | 'GIN' | 'BRIN' | string; export type IndexMethod = 'BTREE' | 'HASH' | 'GIST' | 'SPGIST' | 'GIN' | 'BRIN' | string;
...@@ -436,7 +445,7 @@ export class QueryInterface { ...@@ -436,7 +445,7 @@ export class QueryInterface {
* Inserts or Updates a record in the database * Inserts or Updates a record in the database
*/ */
public upsert( public upsert(
tableName: string, tableName: TableName,
values: object, values: object,
updateValues: object, updateValues: object,
model: typeof Model, model: typeof Model,
...@@ -447,7 +456,7 @@ export class QueryInterface { ...@@ -447,7 +456,7 @@ export class QueryInterface {
* Inserts multiple records at once * Inserts multiple records at once
*/ */
public bulkInsert( public bulkInsert(
tableName: string, tableName: TableName,
records: object[], records: object[],
options?: QueryOptions, options?: QueryOptions,
attributes?: string[] | string attributes?: string[] | string
...@@ -458,7 +467,7 @@ export class QueryInterface { ...@@ -458,7 +467,7 @@ export class QueryInterface {
*/ */
public update( public update(
instance: Model, instance: Model,
tableName: string, tableName: TableName,
values: object, values: object,
identifier: WhereOptions, identifier: WhereOptions,
options?: QueryOptions options?: QueryOptions
...@@ -468,7 +477,7 @@ export class QueryInterface { ...@@ -468,7 +477,7 @@ export class QueryInterface {
* Updates multiple rows at once * Updates multiple rows at once
*/ */
public bulkUpdate( public bulkUpdate(
tableName: string, tableName: TableName,
values: object, values: object,
identifier: WhereOptions, identifier: WhereOptions,
options?: QueryOptions, options?: QueryOptions,
...@@ -478,13 +487,13 @@ export class QueryInterface { ...@@ -478,13 +487,13 @@ export class QueryInterface {
/** /**
* Deletes a row * 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 * Deletes multiple rows at once
*/ */
public bulkDelete( public bulkDelete(
tableName: string, tableName: TableName,
identifier: WhereOptions, identifier: WhereOptions,
options?: QueryOptions, options?: QueryOptions,
model?: typeof Model model?: typeof Model
...@@ -493,14 +502,14 @@ export class QueryInterface { ...@@ -493,14 +502,14 @@ export class QueryInterface {
/** /**
* Returns selected rows * 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 * Increments a row value
*/ */
public increment( public increment(
instance: Model, instance: Model,
tableName: string, tableName: TableName,
values: object, values: object,
identifier: WhereOptions, identifier: WhereOptions,
options?: QueryOptions options?: QueryOptions
...@@ -510,7 +519,7 @@ export class QueryInterface { ...@@ -510,7 +519,7 @@ export class QueryInterface {
* Selects raw without parsing the string into an object * Selects raw without parsing the string into an object
*/ */
public rawSelect( public rawSelect(
tableName: string, tableName: TableName,
options: QueryOptionsWithWhere, options: QueryOptionsWithWhere,
attributeSelector: string | string[], attributeSelector: string | string[],
model?: typeof Model model?: typeof Model
...@@ -521,7 +530,7 @@ export class QueryInterface { ...@@ -521,7 +530,7 @@ export class QueryInterface {
* parameters. * parameters.
*/ */
public createTrigger( public createTrigger(
tableName: string, tableName: TableName,
triggerName: string, triggerName: string,
timingType: string, timingType: string,
fireOnArray: { fireOnArray: {
...@@ -536,13 +545,13 @@ export class QueryInterface { ...@@ -536,13 +545,13 @@ export class QueryInterface {
/** /**
* Postgres only. Drops the specified trigger. * 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 * Postgres only. Renames a trigger
*/ */
public renameTrigger( public renameTrigger(
tableName: string, tableName: TableName,
oldTriggerName: string, oldTriggerName: string,
newTriggerName: string, newTriggerName: string,
options?: QueryInterfaceOptions options?: QueryInterfaceOptions
...@@ -585,7 +594,7 @@ export class QueryInterface { ...@@ -585,7 +594,7 @@ export class QueryInterface {
/** /**
* Escape a table name * 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 * Split an identifier into .-separated tokens and quote each part. If force is true, the identifier will be
......
...@@ -51,6 +51,16 @@ queryInterface.createTable( ...@@ -51,6 +51,16 @@ queryInterface.createTable(
queryInterface.dropTable('nameOfTheExistingTable'); 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.dropAllTables();
queryInterface.renameTable('Person', 'User'); queryInterface.renameTable('Person', 'User');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!