Skip to content

Commit

Permalink
Merge branch 'master' of github.com:schopr9/sequelize
Browse files Browse the repository at this point in the history
  • Loading branch information
schopr9 committed Oct 24, 2019
2 parents 0c038d2 + bc4b927 commit 2c9b14b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/manual/associations.md
@@ -1,6 +1,6 @@
# Associations

This section describes the various association types in sequelize. There are four type of
This section describes the various association types in sequelize. There are four types of
associations available in Sequelize

1. BelongsTo
Expand Down
3 changes: 2 additions & 1 deletion docs/manual/hooks.md
Expand Up @@ -332,7 +332,8 @@ User.beforeBulkCreate((users, options) => {
For the most part hooks will work the same for instances when being associated except a few things

1. When using add/set functions the beforeUpdate/afterUpdate hooks will run.
2. The only way to call beforeDestroy/afterDestroy hooks are on associations with `onDelete: 'cascade'` and the option `hooks: true`. For instance:
2. When using add functions for belongsToMany relationships that will add record to pivot table, beforeBulkCreate/afterBulkCreate hooks in intermediate model will run.
3. The only way to call beforeDestroy/afterDestroy hooks are on associations with `onDelete: 'cascade'` and the option `hooks: true`. For instance:

```js
class Projects extends Model {}
Expand Down
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

0 comments on commit 2c9b14b

Please sign in to comment.