From c111cda3ca500602014a3aecd83e1632eb5707d7 Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Fri, 14 Feb 2020 17:13:08 -0800 Subject: [PATCH] fix(query-interface): allow passing null for query interface insert --- types/lib/model.d.ts | 10 +++++----- types/lib/query-interface.d.ts | 4 ++-- types/test/query-interface.ts | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/types/lib/model.d.ts b/types/lib/model.d.ts index db189970967a..7ce2734b4688 100644 --- a/types/lib/model.d.ts +++ b/types/lib/model.d.ts @@ -151,10 +151,10 @@ export interface WhereOperators { [Op.lte]?: number | string | Date | Literal; /** Example: `[Op.ne]: 20,` becomes `!= 20` */ - [Op.ne]?: string | number | Literal | WhereOperators; + [Op.ne]?: null | string | number | Literal | WhereOperators; /** Example: `[Op.not]: true,` becomes `IS NOT TRUE` */ - [Op.not]?: boolean | string | number | Literal | WhereOperators; + [Op.not]?: null | boolean | string | number | Literal | WhereOperators; /** Example: `[Op.between]: [6, 10],` becomes `BETWEEN 6 AND 10` */ [Op.between]?: [number, number]; @@ -2605,11 +2605,11 @@ export abstract class Model extends Hooks { /** * Validates this instance, and if the validation passes, persists it to the database. - * + * * Returns a Promise that resolves to the saved instance (or rejects with a `Sequelize.ValidationError`, which will have a property for each of the fields for which the validation failed, with the error message for that field). - * + * * This method is optimized to perform an UPDATE only into the fields that changed. If nothing has changed, no SQL query will be performed. - * + * * This method is not aware of eager loaded associations. In other words, if some other model instance (child) was eager loaded with this instance (parent), and you change something in the child, calling `save()` will simply ignore the change that happened on the child. */ public save(options?: SaveOptions): Promise; diff --git a/types/lib/query-interface.d.ts b/types/lib/query-interface.d.ts index a1ea23154090..8e04638ecf85 100644 --- a/types/lib/query-interface.d.ts +++ b/types/lib/query-interface.d.ts @@ -451,7 +451,7 @@ export class QueryInterface { /** * Inserts a new record */ - public insert(instance: Model, tableName: string, values: object, options?: QueryOptions): Promise; + public insert(instance: Model | null, tableName: string, values: object, options?: QueryOptions): Promise; /** * Inserts or Updates a record in the database @@ -473,7 +473,7 @@ export class QueryInterface { records: object[], options?: QueryOptions, attributes?: string[] | string - ): Promise; + ): Promise; /** * Updates a row diff --git a/types/test/query-interface.ts b/types/test/query-interface.ts index ad95eee09a4b..2c02b8db3926 100644 --- a/types/test/query-interface.ts +++ b/types/test/query-interface.ts @@ -53,7 +53,7 @@ queryInterface.dropTable('nameOfTheExistingTable'); queryInterface.bulkDelete({ tableName: 'foo', schema: 'bar' }, {}, {}); -queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {}); +const bulkInsertRes: Promise = queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {}); queryInterface.bulkUpdate({ tableName: 'foo', delimiter: 'bar', as: 'baz', name: 'quz' }, {}, {}); @@ -181,3 +181,5 @@ queryInterface.delete(null, 'Person', { }); queryInterface.upsert("test", {"a": 1}, {"b": 2}, {"c": 3}, Model, {}); + +queryInterface.insert(null, 'test', {});