From 074619ae7356868440751cbc2616141196b61b0a Mon Sep 17 00:00:00 2001 From: Cao Jiannan Date: Tue, 21 Jun 2016 02:21:42 +0800 Subject: [PATCH 1/8] Update for Model static members Update for Model static members Based on http://sequelize.readthedocs.io/en/latest/api/model/, and source code https://github.com/sequelize/sequelize/blob/master/lib/model.js --- sequelize/sequelize.d.ts | 247 +++++++++++++++++++++++++++++++++++---- 1 file changed, 225 insertions(+), 22 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index cc0ff0b4ff..733f31ddad 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -2595,6 +2595,8 @@ declare module "sequelize" { * Transaction to run query under */ transaction? : Transaction; + + } @@ -2683,6 +2685,11 @@ declare module "sequelize" { * Transaction to run the query in */ transaction? : Transaction; + + /** + * Append RETURNING * to get back auto generated values (Postgres only) + */ + returning? : boolean; } @@ -2928,6 +2935,11 @@ declare module "sequelize" { * A function that gets executed while running the query to log the sql. */ logging?: boolean | Function; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark?: boolean; } @@ -2945,8 +2957,32 @@ declare module "sequelize" { * A function that gets executed while running the query to log the sql. */ logging? : Function | boolean; + + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark: boolean; } + /** + * GetTableName Options + */ + interface GetTableNameOptions { + + /** + * A function that gets executed while running the query to log the sql. + */ + logging? : Function | boolean; + + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark: boolean; + + } + /** * AddScope Options for Model.addScope @@ -3125,7 +3161,7 @@ declare module "sequelize" { * * A hash of options to describe the scope of the search */ - interface FindOptions { + interface FindOptions { /** * A hash of attributes to describe your search. See above for examples. @@ -3161,7 +3197,7 @@ declare module "sequelize" { * `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not. */ order?: string | col | literal | Array | { model : Model, as? : string}> | Array | { model : Model, as? : string}>>; - + /** * Limit the results */ @@ -3204,6 +3240,33 @@ declare module "sequelize" { * https://github.com/sequelize/sequelize/blob/master/docs/docs/models-usage.md#user-content-manipulating-the-dataset-with-limit-offset-order-and-group */ group?: string | string[] | Object; + + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark? : boolean; + + } + + /** + * Options for findById/findByPrimary, findOne/find + */ + interface FindOneOptions { + + /** + * Transaction to run query under + */ + transaction? : Transaction; + + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; } @@ -3239,12 +3302,25 @@ declare module "sequelize" { */ group? : Object; + /** + * Transaction to run query under + */ + transaction? : Transaction; + /** * A function that gets executed while running the query to log the sql. */ logging? : boolean | Function; - transaction?: Transaction; + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark? : boolean; } /** @@ -3269,6 +3345,15 @@ declare module "sequelize" { */ include? : Array | IncludeOptions>; + /** + * If true, the updatedAt timestamp will not be updated. + */ + silent? : boolean; + + /** + * Append RETURNING * to get back auto generated values (Postgres only) + */ + returning? : boolean; } /** @@ -3295,10 +3380,16 @@ declare module "sequelize" { * A function that gets executed while running the query to log the sql. */ logging? : boolean | Function; + + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; - silent? : boolean; - - returning? : boolean; + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark? : boolean; } /** @@ -3326,6 +3417,26 @@ declare module "sequelize" { */ logging? : boolean | Function; + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark? : boolean; + } + + /** + * Options for Model.findOrInitialize method + */ + interface FindCreateFindOptions { + + /** + * A hash of search attributes. + */ + where : string | WhereOptions; + + /** + * Default values to use if building a new instance + */ + defaults? : TAttributes; } /** @@ -3343,15 +3454,15 @@ declare module "sequelize" { */ fields? : string[]; - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - /** * Transaction to run query under */ transaction? : Transaction; + + /** + * A function that gets executed while running the query to log the sql. + */ + logging? : boolean | Function; /** * An optional parameter to specify the schema search_path (Postgres only) @@ -3414,6 +3525,20 @@ declare module "sequelize" { */ logging? : boolean | Function; + /** + * Append RETURNING * to get back auto generated values (Postgres only). + */ + returning? : boolean; + + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark? : boolean; } /** @@ -3439,6 +3564,15 @@ declare module "sequelize" { */ logging? : boolean | Function; + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark? : boolean; } /** @@ -3515,7 +3649,12 @@ declare module "sequelize" { * Transaction to run query under */ transaction? : Transaction; - + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark?: boolean; + } /** @@ -3582,18 +3721,33 @@ declare module "sequelize" { * Transaction to run query under */ transaction? : Transaction; - + + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark?: boolean; + + /** + * If true, the updatedAt timestamp will not be updated. + */ + silent? : boolean; } /** * Options used for Model.aggregate */ - interface AggregateOptions extends QueryOptions { + interface AggregateOptions { /** * A hash of search attributes. */ where?: WhereOptions; + + /** + * A function that gets executed while running the query to log the sql. + */ + logging? : boolean | Function; /** * The type of the result. If `field` is a field in this Model, the default will be the type of that field, @@ -3605,7 +3759,23 @@ declare module "sequelize" { * Applies DISTINCT to the field being aggregated over */ distinct? : boolean; + + /** + * The transaction that the query should be executed under + */ + transaction?: Transaction; + /** + * When `true`, the first returned value of `aggregateFunction` is cast to `dataType` and returned. + * If additional attributes are specified, along with `group` clauses, set `plain` to `false` to return all values of all returned rows. + * Defaults to `true` + */ + plain?: boolean; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark?: boolean; } /** @@ -3661,7 +3831,7 @@ declare module "sequelize" { * subscribers_1, subscribers_2) * @param options.logging=false A function that gets executed while running the query to log the sql. */ - getTableName( options? : { logging : Function } ) : string | Object; + getTableName( options? : GetTableNameOptions ) : string | Object; /** * Add a new scope to the model. This is especially useful for adding scopes with includes, when the model you want to include is not available at the time this model is defined. @@ -3793,15 +3963,15 @@ declare module "sequelize" { * Search for a single instance by its primary key. This applies LIMIT 1, so the listener will * always be called with a single instance. */ - findById( identifier? : number | string, options? : FindOptions ) : Promise; - findByPrimary( identifier? : number | string, options? : FindOptions ) : Promise; + findById( identifier? : number | string, options? : FindOneOptions ) : Promise; + findByPrimary( identifier? : number | string, options? : FindOneOptions ) : Promise; /** * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single * instance. */ - findOne( options? : FindOptions ) : Promise; - find( optionz? : FindOptions ) : Promise; + findOne( options? : FindOneOptions ) : Promise; + find( optionz? : FindOneOptions ) : Promise; /** * Run an aggregation method on the specified field @@ -3908,6 +4078,12 @@ declare module "sequelize" { * will be created instead, and any unique constraint violation will be handled internally. */ findOrCreate( options : FindOrInitializeOptions ) : Promise; + + /** + * A more performant findOrCreate that will not work under a transaction (at least not in postgres) + * Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again + */ + findCreateFind( options : FindCreateFindOptions ) : Promise; /** * Insert or update a single row. An update will be executed if a row which matches the supplied values on @@ -4532,6 +4708,12 @@ declare module "sequelize" { * replacements to replace `?` in your SQL. */ replacements? : Object | string[]; + + /** + * Either an object of named bind parameter in the format `$param` or an array of unnamed + * bind parameter to replace `$1`, `$2`, ... in your SQL. + */ + bind?: Object | string[]; /** * Force the query to use the write pool, regardless of the query type. @@ -4554,9 +4736,30 @@ declare module "sequelize" { * A sequelize model used to build the returned model instances (used to be called callee) */ model? : Model; - + + /** + * Set of flags that control when a query is automatically retried. + */ + retry? : {match?: string[], max?: integer}; + + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; + + /** + * If false do not prepend the query with the search_path (Postgres only) + */ + supportsSearchPath : boolean; + + /** + * Map returned fields to model's fields if `options.model` or `options.instance` is present. + * Mapping will occur before building the model instance. + */ + mapToModel : boolean; + // TODO: force, cascade - + fieldMap? : { [key: string]: string; } } /** @@ -6197,4 +6400,4 @@ declare module "sequelize" { export = sequelize; -} \ No newline at end of file +} From b1e672d9a631cb4d28b326560d03f1344f16a166 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Tue, 21 Jun 2016 09:55:34 +0800 Subject: [PATCH 2/8] update Model static function options --- sequelize/sequelize.d.ts | 381 +++++++++------------------------------ 1 file changed, 85 insertions(+), 296 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 733f31ddad..b9fe2664e3 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -2595,9 +2595,6 @@ declare module "sequelize" { * Transaction to run query under */ transaction? : Transaction; - - - } /** @@ -2654,7 +2651,7 @@ declare module "sequelize" { /** * Options used for Instance.save method */ - interface InstanceSaveOptions { + interface InstanceSaveOptions extends LoggingOptions, ReturningOptions { /** * An optional array of strings, representing database columns. If fields is provided, only those columns @@ -2676,21 +2673,6 @@ declare module "sequelize" { */ validate? : boolean; - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * Transaction to run the query in - */ - transaction? : Transaction; - - /** - * Append RETURNING * to get back auto generated values (Postgres only) - */ - returning? : boolean; - } /** @@ -2914,6 +2896,27 @@ declare module "sequelize" { } + interface LoggingOptions { + logging?: boolean | Function; + + /** + * Print query execution time in milliseconds when logging SQL. + */ + benchmark?: boolean; + } + + interface SearchPathOptions { + /** + * Transaction to run query under + */ + transaction? : Transaction; + + /** + * An optional parameter to specify the schema search_path (Postgres only) + */ + searchPath? : string; + } + // // Model // ~~~~~~~ @@ -2924,76 +2927,44 @@ declare module "sequelize" { /** * Options to pass to Model on drop */ - interface DropOptions { + interface DropOptions extends LoggingOptions { /** * Also drop all objects depending on this table, such as views. Only works in postgres */ cascade?: boolean; - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark?: boolean; - } /** * Schema Options provided for applying a schema to a model */ - interface SchemaOptions { + interface SchemaOptions extends LoggingOptions { /** * The character(s) that separates the schema name from the table name */ schemaDelimeter? : string; - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : Function | boolean; - - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark: boolean; - } /** * GetTableName Options */ - interface GetTableNameOptions { - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : Function | boolean; - - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark: boolean; - + interface GetTableNameOptions extends LoggingOptions { + // no addition properties } - + /** * AddScope Options for Model.addScope */ interface AddScopeOptions { - + /** * If a scope of the same name already exists, should it be overwritten? */ override: boolean; - + } /** @@ -3161,7 +3132,7 @@ declare module "sequelize" { * * A hash of options to describe the scope of the search */ - interface FindOptions { + interface FindOptions extends LoggingOptions, SearchPathOptions { /** * A hash of attributes to describe your search. See above for examples. @@ -3197,7 +3168,7 @@ declare module "sequelize" { * `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not. */ order?: string | col | literal | Array | { model : Model, as? : string}> | Array | { model : Model, as? : string}>>; - + /** * Limit the results */ @@ -3208,11 +3179,6 @@ declare module "sequelize" { */ offset?: number; - /** - * Transaction to run query under - */ - transaction? : Transaction; - /** * Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. * Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model @@ -3225,11 +3191,6 @@ declare module "sequelize" { */ raw? : boolean; - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - /** * having ?!? */ @@ -3240,40 +3201,27 @@ declare module "sequelize" { * https://github.com/sequelize/sequelize/blob/master/docs/docs/models-usage.md#user-content-manipulating-the-dataset-with-limit-offset-order-and-group */ group?: string | string[] | Object; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } - + /** - * Options for findById/findByPrimary, findOne/find + * Options for findOne/find */ - interface FindOneOptions { - - /** - * Transaction to run query under - */ - transaction? : Transaction; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; + interface FindOneOptions extends SearchPathOptions { + // no additional properties + } + /** + * Options for findById/findByPrimary, + */ + interface FindByIdOptions extends SearchPathOptions { + // no additional properties } /** * Options for Model.count method */ - interface CountOptions { + interface CountOptions extends LoggingOptions, SearchPathOptions { /** * A hash of search attributes. @@ -3301,32 +3249,12 @@ declare module "sequelize" { * TODO: Check? */ group? : Object; - - /** - * Transaction to run query under - */ - transaction? : Transaction; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } /** * Options for Model.build method */ - interface BuildOptions { + interface BuildOptions extends ReturningOptions { /** * If set to true, values will ignore field and virtual setters. @@ -3345,22 +3273,16 @@ declare module "sequelize" { */ include? : Array | IncludeOptions>; - /** - * If true, the updatedAt timestamp will not be updated. - */ - silent? : boolean; - /** - * Append RETURNING * to get back auto generated values (Postgres only) + * If true, the updatedAt timestamp will not be updated. */ - returning? : boolean; + silent? : boolean; } /** * Options for Model.create method */ - interface CreateOptions extends BuildOptions { - + interface CreateOptions extends BuildOptions, InstanceSaveOptions { /** * If set, only columns matching those in fields will be saved */ @@ -3370,32 +3292,12 @@ declare module "sequelize" { * On Duplicate */ onDuplicate? : string; - - /** - * Transaction to run query under - */ - transaction? : Transaction; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } /** * Options for Model.findOrInitialize method */ - interface FindOrInitializeOptions { + interface FindOrInitializeOptions extends LoggingOptions { /** * A hash of search attributes. @@ -3411,18 +3313,8 @@ declare module "sequelize" { * Transaction to run query under */ transaction? : Transaction; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } - + /** * Options for Model.findOrInitialize method */ @@ -3442,7 +3334,7 @@ declare module "sequelize" { /** * Options for Model.upsert method */ - interface UpsertOptions { + interface UpsertOptions extends LoggingOptions, SearchPathOptions { /** * Run validations before the row is inserted @@ -3453,32 +3345,12 @@ declare module "sequelize" { * The fields to insert / update. Defaults to all fields */ fields? : string[]; - - /** - * Transaction to run query under - */ - transaction? : Transaction; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } /** * Options for Model.bulkCreate method */ - interface BulkCreateOptions { + interface BulkCreateOptions extends LoggingOptions, SearchPathOptions, ReturningOptions { /** * Fields to insert (defaults to all fields) @@ -3514,42 +3386,12 @@ declare module "sequelize" { * mariadb). By default, all fields are updated. */ updateOnDuplicate? : string[]; - - /** - * Transaction to run query under - */ - transaction? : Transaction; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * Append RETURNING * to get back auto generated values (Postgres only). - */ - returning? : boolean; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } /** * The options passed to Model.destroy in addition to truncate */ - interface TruncateOptions { - - /** - * Transaction to run query under - */ - transaction? : Transaction; + interface TruncateOptions extends LoggingOptions, SearchPathOptions { /** * Only used in conjuction with TRUNCATE. Truncates all tables that have foreign-key references to the @@ -3558,21 +3400,6 @@ declare module "sequelize" { * Defaults to false; */ cascade? : boolean; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark? : boolean; } /** @@ -3617,7 +3444,7 @@ declare module "sequelize" { /** * Options for Model.restore */ - interface RestoreOptions { + interface RestoreOptions extends LoggingOptions { /** * Filter the restore @@ -3640,27 +3467,17 @@ declare module "sequelize" { */ limit? : number; - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - /** * Transaction to run query under */ transaction? : Transaction; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark?: boolean; - + } /** * Options used for Model.update */ - interface UpdateOptions { + interface UpdateOptions extends LoggingOptions, ReturningOptions { /** * Options to describe the scope of the search. @@ -3702,52 +3519,31 @@ declare module "sequelize" { */ individualHooks? : boolean; - /** - * Return the affected rows (only for postgres) - */ - returning? : boolean; - /** * How many rows to update (only for mysql and mariadb) */ limit? : number; - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; - /** * Transaction to run query under */ transaction? : Transaction; - - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark?: boolean; - + /** - * If true, the updatedAt timestamp will not be updated. - */ + * If true, the updatedAt timestamp will not be updated. + */ silent? : boolean; } /** * Options used for Model.aggregate */ - interface AggregateOptions { + interface AggregateOptions extends LoggingOptions { /** * A hash of search attributes. */ where?: WhereOptions; - - /** - * A function that gets executed while running the query to log the sql. - */ - logging? : boolean | Function; /** * The type of the result. If `field` is a field in this Model, the default will be the type of that field, @@ -3759,7 +3555,7 @@ declare module "sequelize" { * Applies DISTINCT to the field being aggregated over */ distinct? : boolean; - + /** * The transaction that the query should be executed under */ @@ -3771,11 +3567,6 @@ declare module "sequelize" { * Defaults to `true` */ plain?: boolean; - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark?: boolean; } /** @@ -3963,15 +3754,15 @@ declare module "sequelize" { * Search for a single instance by its primary key. This applies LIMIT 1, so the listener will * always be called with a single instance. */ - findById( identifier? : number | string, options? : FindOneOptions ) : Promise; - findByPrimary( identifier? : number | string, options? : FindOneOptions ) : Promise; + findById( identifier? : number | string, options? : FindByIdOptions ) : Promise; + findByPrimary( identifier? : number | string, options? : FindByIdOptions ) : Promise; /** * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single * instance. */ findOne( options? : FindOneOptions ) : Promise; - find( optionz? : FindOneOptions ) : Promise; + find( options? : FindOneOptions ) : Promise; /** * Run an aggregation method on the specified field @@ -4078,7 +3869,7 @@ declare module "sequelize" { * will be created instead, and any unique constraint violation will be handled internally. */ findOrCreate( options : FindOrInitializeOptions ) : Promise; - + /** * A more performant findOrCreate that will not work under a transaction (at least not in postgres) * Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again @@ -4669,7 +4460,7 @@ declare module "sequelize" { * * @see Options */ - interface QueryOptions { + interface QueryOptions extends SearchPathOptions, ReturningOptions { /** * If true, sequelize will not try to format the results of the query, or build an instance of a model from @@ -4677,10 +4468,6 @@ declare module "sequelize" { */ raw?: boolean; - /** - * The transaction that the query should be executed under - */ - transaction?: Transaction; /** * The type of query you are executing. The query type affects how results are formatted before they are @@ -4708,7 +4495,7 @@ declare module "sequelize" { * replacements to replace `?` in your SQL. */ replacements? : Object | string[]; - + /** * Either an object of named bind parameter in the format `$param` or an array of unnamed * bind parameter to replace `$1`, `$2`, ... in your SQL. @@ -4725,7 +4512,7 @@ declare module "sequelize" { /** * A function that gets executed while running the query to log the sql. */ - logging? : Function; + logging? : boolean | Function; /** * A sequelize instance used to build the return instance @@ -4736,30 +4523,32 @@ declare module "sequelize" { * A sequelize model used to build the returned model instances (used to be called callee) */ model? : Model; - + /** * Set of flags that control when a query is automatically retried. */ - retry? : {match?: string[], max?: integer}; - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath? : string; - + retry? : {match?: string[], max?: number}; + /** * If false do not prepend the query with the search_path (Postgres only) */ - supportsSearchPath : boolean; - - /** - * Map returned fields to model's fields if `options.model` or `options.instance` is present. - * Mapping will occur before building the model instance. - */ - mapToModel : boolean; - + supportsSearchPath : boolean; + + /** + * Map returned fields to model's fields if `options.model` or `options.instance` is present. + * Mapping will occur before building the model instance. + */ + mapToModel : boolean; + // TODO: force, cascade - fieldMap? : { [key: string]: string; } + fieldMap? : { [key: string]: string; } + } + + interface ReturningOptions { + /** + * Append RETURNING * to get back auto generated values (Postgres only) + */ + returning? : boolean; } /** From a4f740bb6ff44a38fed0fdd1ae1c1e7cf917a8d8 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Tue, 21 Jun 2016 10:01:49 +0800 Subject: [PATCH 3/8] create small common interface --- sequelize/sequelize.d.ts | 84 +++++++++++----------------------------- 1 file changed, 23 insertions(+), 61 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index b9fe2664e3..219a1944f8 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -2651,13 +2651,7 @@ declare module "sequelize" { /** * Options used for Instance.save method */ - interface InstanceSaveOptions extends LoggingOptions, ReturningOptions { - - /** - * An optional array of strings, representing database columns. If fields is provided, only those columns - * will be validated and saved. - */ - fields? : string[]; + interface InstanceSaveOptions extends FieldsOptions, LoggingOptions, ReturningOptions { /** * If true, the updatedAt timestamp will not be updated. @@ -2666,13 +2660,6 @@ declare module "sequelize" { */ silent? : boolean; - /** - * If false, validations won't be run. - * - * Defaults to true - */ - validate? : boolean; - } /** @@ -2917,6 +2904,25 @@ declare module "sequelize" { searchPath? : string; } + interface ReturningOptions { + /** + * Append RETURNING * to get back auto generated values (Postgres only) + */ + returning? : boolean; + } + + interface FieldsOptions { + /** + * Run validations before the row is inserted + */ + validate? : boolean; + + /** + * The fields to insert / update. Defaults to all fields + */ + fields? : string[]; + } + // // Model // ~~~~~~~ @@ -3283,10 +3289,6 @@ declare module "sequelize" { * Options for Model.create method */ interface CreateOptions extends BuildOptions, InstanceSaveOptions { - /** - * If set, only columns matching those in fields will be saved - */ - fields? : string[]; /** * On Duplicate @@ -3334,34 +3336,14 @@ declare module "sequelize" { /** * Options for Model.upsert method */ - interface UpsertOptions extends LoggingOptions, SearchPathOptions { - - /** - * Run validations before the row is inserted - */ - validate? : boolean; - - /** - * The fields to insert / update. Defaults to all fields - */ - fields? : string[]; + interface UpsertOptions extends FieldsOptions, LoggingOptions, SearchPathOptions { } /** * Options for Model.bulkCreate method */ - interface BulkCreateOptions extends LoggingOptions, SearchPathOptions, ReturningOptions { - /** - * Fields to insert (defaults to all fields) - */ - fields? : string[]; - - /** - * Should each row be subject to validation before it is inserted. The whole insert will fail if one row - * fails validation - */ - validate? : boolean; + interface BulkCreateOptions extends FieldsOptions, LoggingOptions, SearchPathOptions, ReturningOptions { /** * Run before / after bulk create hooks? @@ -3477,26 +3459,13 @@ declare module "sequelize" { /** * Options used for Model.update */ - interface UpdateOptions extends LoggingOptions, ReturningOptions { + interface UpdateOptions extends FieldsOptions, LoggingOptions, ReturningOptions { /** * Options to describe the scope of the search. */ where: WhereOptions; - /** - * Fields to update (defaults to all fields) - */ - fields? : string[]; - - /** - * Should each row be subject to validation before it is inserted. The whole insert will fail if one row - * fails validation. - * - * Defaults to true - */ - validate? : boolean; - /** * Run before / after bulk update hooks? * @@ -4544,13 +4513,6 @@ declare module "sequelize" { fieldMap? : { [key: string]: string; } } - interface ReturningOptions { - /** - * Append RETURNING * to get back auto generated values (Postgres only) - */ - returning? : boolean; - } - /** * Model validations, allow you to specify format/content/inheritance validations for each attribute of the * model. From 55322ce92ebdfaa483ea7ca992c19c49f768d523 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Tue, 21 Jun 2016 10:07:14 +0800 Subject: [PATCH 4/8] remove silent from BuildOptions --- sequelize/sequelize.d.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 219a1944f8..222cf227d3 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -3278,11 +3278,6 @@ declare module "sequelize" { * TODO: See set */ include? : Array | IncludeOptions>; - - /** - * If true, the updatedAt timestamp will not be updated. - */ - silent? : boolean; } /** From bb940aa5bbaec12a9b56e0b296800f4033e303c5 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Tue, 21 Jun 2016 11:33:53 +0800 Subject: [PATCH 5/8] remove FindOne/FindById Options --- sequelize/sequelize.d.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 222cf227d3..02615e2f1e 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -3210,20 +3210,6 @@ declare module "sequelize" { } - /** - * Options for findOne/find - */ - interface FindOneOptions extends SearchPathOptions { - // no additional properties - } - - /** - * Options for findById/findByPrimary, - */ - interface FindByIdOptions extends SearchPathOptions { - // no additional properties - } - /** * Options for Model.count method */ @@ -3718,15 +3704,15 @@ declare module "sequelize" { * Search for a single instance by its primary key. This applies LIMIT 1, so the listener will * always be called with a single instance. */ - findById( identifier? : number | string, options? : FindByIdOptions ) : Promise; - findByPrimary( identifier? : number | string, options? : FindByIdOptions ) : Promise; + findById( identifier? : number | string, options? : FindOptions ) : Promise; + findByPrimary( identifier? : number | string, options? : FindOptions ) : Promise; /** * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single * instance. */ - findOne( options? : FindOneOptions ) : Promise; - find( options? : FindOneOptions ) : Promise; + findOne( options? : FindOptions ) : Promise; + find( options? : FindOptions ) : Promise; /** * Run an aggregation method on the specified field From 620e3419539bd4e3f7572124a913c2e233bad925 Mon Sep 17 00:00:00 2001 From: frogcjn Date: Wed, 22 Jun 2016 10:03:40 +0800 Subject: [PATCH 6/8] fix error on searchpath options --- sequelize/sequelize.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 02615e2f1e..7fb9b764ed 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -2651,7 +2651,7 @@ declare module "sequelize" { /** * Options used for Instance.save method */ - interface InstanceSaveOptions extends FieldsOptions, LoggingOptions, ReturningOptions { + interface InstanceSaveOptions extends FieldsOptions, LoggingOptions, ReturningOptions, SearchPathOptions { /** * If true, the updatedAt timestamp will not be updated. @@ -4482,7 +4482,7 @@ declare module "sequelize" { /** * If false do not prepend the query with the search_path (Postgres only) */ - supportsSearchPath : boolean; + supportsSearchPath? : boolean; /** * Map returned fields to model's fields if `options.model` or `options.instance` is present. From 83a9ac9c04d306eb89279e24fc1ac13b7e9cdb5a Mon Sep 17 00:00:00 2001 From: frogcjn Date: Wed, 22 Jun 2016 10:06:59 +0800 Subject: [PATCH 7/8] fix eroor on QueryOptions --- sequelize/sequelize.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 7fb9b764ed..af97bfaeda 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -4488,7 +4488,7 @@ declare module "sequelize" { * Map returned fields to model's fields if `options.model` or `options.instance` is present. * Mapping will occur before building the model instance. */ - mapToModel : boolean; + mapToModel? : boolean; // TODO: force, cascade fieldMap? : { [key: string]: string; } From 457de5356265b4a2f2c2b74138c4da8fddc94baf Mon Sep 17 00:00:00 2001 From: frogcjn Date: Wed, 22 Jun 2016 13:42:14 +0800 Subject: [PATCH 8/8] add comment for logging --- sequelize/sequelize.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index af97bfaeda..38072ee079 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -2884,6 +2884,10 @@ declare module "sequelize" { } interface LoggingOptions { + /** + * A function that gets executed while running the query to log the sql. + */ + logging?: boolean | Function; /**