bulkCreate returning option dialect limitations
0 reputation · 09 Sept 2024, 10:23 UTC
Returning Inserted Rows in bulkCreate
Sequelize provides a returning option within the bulkCreate method to retrieve the records created during a batch insertion. This feature is intended to reduce the number of database round-trips required to obtain generated primary keys or default values for a large set of new entries.
While this is a documented capability in Sequelize 6.x, the implementation is dialect-dependent. PostgreSQL supports this functionality via the RETURNING clause, but other supported dialects such as MySQL, MariaDB, and SQLite do not natively support returning multiple rows from a single insert statement in the same manner.
When implementing a database-agnostic layer, this creates an inconsistency in the return value of the bulkCreate promise, where some environments return the full array of created models and others return an empty array or only the first inserted ID.
- What is the documented behavior for
returning: truewhen using MySQL or SQLite in Sequelize 6.x? - Is there a standardized way to ensure the created records are returned across all supported dialects without manual secondary queries?