Skip to content

Commit

Permalink
fix(query-interface): allow passing null for query interface insert
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSchick committed Feb 15, 2020
1 parent bbf9139 commit c111cda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions types/lib/model.d.ts
Expand Up @@ -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];
Expand Down Expand Up @@ -2605,11 +2605,11 @@ export abstract class Model<T = any, T2 = any> 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<this>;
Expand Down
4 changes: 2 additions & 2 deletions types/lib/query-interface.d.ts
Expand Up @@ -451,7 +451,7 @@ export class QueryInterface {
/**
* Inserts a new record
*/
public insert(instance: Model, tableName: string, values: object, options?: QueryOptions): Promise<object>;
public insert(instance: Model | null, tableName: string, values: object, options?: QueryOptions): Promise<object>;

/**
* Inserts or Updates a record in the database
Expand All @@ -473,7 +473,7 @@ export class QueryInterface {
records: object[],
options?: QueryOptions,
attributes?: string[] | string
): Promise<object>;
): Promise<object | number>;

/**
* Updates a row
Expand Down
4 changes: 3 additions & 1 deletion types/test/query-interface.ts
Expand Up @@ -53,7 +53,7 @@ queryInterface.dropTable('nameOfTheExistingTable');

queryInterface.bulkDelete({ tableName: 'foo', schema: 'bar' }, {}, {});

queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {});
const bulkInsertRes: Promise<number | object> = queryInterface.bulkInsert({ tableName: 'foo', as: 'bar', name: 'as' }, [{}], {});

queryInterface.bulkUpdate({ tableName: 'foo', delimiter: 'bar', as: 'baz', name: 'quz' }, {}, {});

Expand Down Expand Up @@ -181,3 +181,5 @@ queryInterface.delete(null, 'Person', {
});

queryInterface.upsert("test", {"a": 1}, {"b": 2}, {"c": 3}, Model, {});

queryInterface.insert(null, 'test', {});

0 comments on commit c111cda

Please sign in to comment.