不要怂,就是干,撸起袖子干!

Commit 761158cc by Simon Schick Committed by GitHub

fix(query-interface): allow passing null for query interface insert (#11931)

1 parent f1ba2808
...@@ -151,10 +151,10 @@ export interface WhereOperators { ...@@ -151,10 +151,10 @@ export interface WhereOperators {
[Op.lte]?: number | string | Date | Literal; [Op.lte]?: number | string | Date | Literal;
/** Example: `[Op.ne]: 20,` becomes `!= 20` */ /** 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` */ /** 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` */ /** Example: `[Op.between]: [6, 10],` becomes `BETWEEN 6 AND 10` */
[Op.between]?: [number, number]; [Op.between]?: [number, number];
...@@ -2605,11 +2605,11 @@ export abstract class Model<T = any, T2 = any> extends Hooks { ...@@ -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. * 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). * 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 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. * 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>; public save(options?: SaveOptions): Promise<this>;
......
...@@ -451,7 +451,7 @@ export class QueryInterface { ...@@ -451,7 +451,7 @@ export class QueryInterface {
/** /**
* Inserts a new record * 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 * Inserts or Updates a record in the database
...@@ -473,7 +473,7 @@ export class QueryInterface { ...@@ -473,7 +473,7 @@ export class QueryInterface {
records: object[], records: object[],
options?: QueryOptions, options?: QueryOptions,
attributes?: string[] | string attributes?: string[] | string
): Promise<object>; ): Promise<object | number>;
/** /**
* Updates a row * Updates a row
......
...@@ -53,7 +53,7 @@ queryInterface.dropTable('nameOfTheExistingTable'); ...@@ -53,7 +53,7 @@ queryInterface.dropTable('nameOfTheExistingTable');
queryInterface.bulkDelete({ tableName: 'foo', schema: 'bar' }, {}, {}); 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' }, {}, {}); queryInterface.bulkUpdate({ tableName: 'foo', delimiter: 'bar', as: 'baz', name: 'quz' }, {}, {});
...@@ -181,3 +181,5 @@ queryInterface.delete(null, 'Person', { ...@@ -181,3 +181,5 @@ queryInterface.delete(null, 'Person', {
}); });
queryInterface.upsert("test", {"a": 1}, {"b": 2}, {"c": 3}, Model, {}); queryInterface.upsert("test", {"a": 1}, {"b": 2}, {"c": 3}, Model, {});
queryInterface.insert(null, 'test', {});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!