diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index 5bb602388a..7524162a1b 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -1,6 +1,10 @@ // Type definitions for Sequelize 4.0.0 // Project: http://sequelizejs.com -// Definitions by: samuelneff , Peter Harris , Ivan Drinchev , Brendan Abolivier +// Definitions by: samuelneff +// Peter Harris +// Ivan Drinchev +// Brendan Abolivier +// Patsakol Tangjitcharoenchai // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -4613,7 +4617,7 @@ declare namespace sequelize { /** * Set of flags that control when a query is automatically retried. */ - retry?: { match?: string[], max?: number }; + retry?: RetryOptions; /** * If false do not prepend the query with the search_path (Postgres only) @@ -5205,6 +5209,25 @@ declare namespace sequelize { } + /** + * Interface for retry Options in the sequelize constructor and QueryOptions + * + * @see Options, QueryOptions + */ + interface RetryOptions { + + /** + * Only retry a query if the error matches one of these strings. + */ + match?: string[]; + + /** + * How many times a failing query is automatically retried. Set to 0 to disable retrying on SQL_BUSY error. + */ + max?: number + + } + /** * Options for the constructor of Sequelize main class */ @@ -5254,6 +5277,21 @@ declare namespace sequelize { */ protocol?: string; + /** + * The username which is used to authenticate against the database. + */ + username?: string; + + /** + * The password which is used to authenticate against the database. + */ + password?: string; + + /** + * The name of the database + */ + database?: string; + /** * Default options for model definitions. See sequelize.define for options */ @@ -5317,6 +5355,19 @@ declare namespace sequelize { */ replication?: ReplicationOptions; + /** + * Set of flags that control when a query is automatically retried. + */ + retry?: RetryOptions; + + /** + * Run built in type validators on insert and update, + * e.g. validate that arguments passed to integer fields are integer-like. + * + * Defaults to false + */ + typeValidation?: boolean; + /** * Connection pool options */ @@ -5541,6 +5592,15 @@ declare namespace sequelize { */ new (uri: string, options?: Options): Sequelize; + /** + * Instantiate sequelize with an options object which containing username, password, database + * @name Sequelize + * @constructor + * + * @param options An object with options. See above for possible options + */ + new (options: Options): Sequelize; + /** * Provide access to continuation-local-storage (http://docs.sequelizejs.com/en/latest/api/sequelize/#transactionoptions-promise) */ @@ -5577,6 +5637,11 @@ declare namespace sequelize { */ models: ModelsHashInterface; + /** + * Defined options. + */ + options: Options; + /** * Returns the specified dialect. */ diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index c2a171109f..aa14079e9d 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -1193,6 +1193,16 @@ new Sequelize( 'sequelize', null, null, { } } } ); +new Sequelize( { + database: 'db', + username: 'user', + password: 'pass', + retry: { + match: ['failed'], + max: 3 + }, + typeValidation: true +} ); s.model( 'Project' ); s.models['Project']; diff --git a/types/sequelize/v3/index.d.ts b/types/sequelize/v3/index.d.ts index 6d55a66b5a..bb9511c5ed 100644 --- a/types/sequelize/v3/index.d.ts +++ b/types/sequelize/v3/index.d.ts @@ -4509,7 +4509,7 @@ declare namespace sequelize { /** * Set of flags that control when a query is automatically retried. */ - retry?: { match?: string[], max?: number }; + retry?: RetryOptions; /** * If false do not prepend the query with the search_path (Postgres only) @@ -5069,6 +5069,25 @@ declare namespace sequelize { } + /** + * Interface for retry Options in the sequelize constructor and QueryOptions + * + * @see Options, QueryOptions + */ + interface RetryOptions { + + /** + * Only retry a query if the error matches one of these strings. + */ + match?: string[]; + + /** + * How many times a failing query is automatically retried. Set to 0 to disable retrying on SQL_BUSY error. + */ + max?: number + + } + /** * Options for the constructor of Sequelize main class */ @@ -5118,6 +5137,21 @@ declare namespace sequelize { */ protocol?: string; + /** + * The username which is used to authenticate against the database. + */ + username?: string; + + /** + * The password which is used to authenticate against the database. + */ + password?: string; + + /** + * The name of the database + */ + database?: string; + /** * Default options for model definitions. See sequelize.define for options */ @@ -5181,6 +5215,11 @@ declare namespace sequelize { */ replication?: ReplicationOptions; + /** + * Set of flags that control when a query is automatically retried. + */ + retry?: RetryOptions; + /** * Connection pool options */ @@ -5405,6 +5444,15 @@ declare namespace sequelize { */ new (uri: string, options?: Options): Sequelize; + /** + * Instantiate sequelize with an options object which containing username, password, database + * @name Sequelize + * @constructor + * + * @param options An object with options. See above for possible options + */ + new (options: Options): Sequelize; + /** * Provide access to continuation-local-storage (http://docs.sequelizejs.com/en/latest/api/sequelize/#transactionoptions-promise) */ @@ -5441,6 +5489,11 @@ declare namespace sequelize { */ models: ModelsHashInterface; + /** + * Defined options. + */ + options: Options; + /** * Returns the specified dialect. */ diff --git a/types/sequelize/v3/sequelize-tests.ts b/types/sequelize/v3/sequelize-tests.ts index 78a89ed2d4..3f1ef022bb 100644 --- a/types/sequelize/v3/sequelize-tests.ts +++ b/types/sequelize/v3/sequelize-tests.ts @@ -1170,6 +1170,15 @@ new Sequelize( 'sequelize', null, null, { } } } ); +new Sequelize( { + database: 'db', + username: 'user', + password: 'pass', + retry: { + match: ['failed'], + max: 3 + } +} ); s.model( 'Project' ); s.models['Project'];