queryInterface.bulkInsert behaviour in SQLite / MySQL / PostreSQL is different
See original GitHub issueWhat are you doing?
const battlefield = await queryInterface.bulkInsert(
'battlefields',
[
{
owner: user1,
game,
},
{
owner: user2,
game
},
],
{}
);
if you execute it against MySQL it will return 1st created ID. e.g 1 if you execute it against SQLite it will return last created ID. e.g 2
To Reproduce git clone from this branch/PR https://github.com/eugene-matvejev/node-js-battleship/pull/1 commit hash: 0452f13828a4223c1dcea87c7d6004fb4ae20b77
MySQL:
$ npm i
setup your mysql with root/password as credentials
$ npm run sequlize db:create
$ npm run sequlize db:migrate
$ npm run sequlize db:seed:all
observe in console logs:
== 20190708135942-example-game: migrating =======
{ battlefield: 1 }
== 20190708135942-example-game: migrated (0.015s)
SQLite:
$ npm i
$ npm test
observe in console logs:
Executing (default): INSERT INTO `battlefields` (`owner`,`game`) VALUES (3,1),(4,1);
console.log undefined:45
{ battlefield: 2 }
What do you expect to happen?
id should be last or/and first for every dialect
What is actually happening?
one got last insert, another got first insert
Output, either JSON or SQL
Environment
Sequelize CLI [Node: 10.16.0, CLI: 5.5.0, ORM: 5.8.12] Dialect:
- [ x ] mysql
- postgres
- [ x ] sqlite
- mssql
- any Dialect library version: 5.8.12 Database version: 5.7.26 Sequelize version: 5.8.12 Node Version: 10.16.0 OS: MacBook If TypeScript related: TypeScript version: XXX Tested with latest release:
- [ x ] No
- Yes, specify that version:
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
SQLite vs MySQL vs PostgreSQL: A Comparison Of Relational ...
This article compares and contrasts three of the most widely implemented open-source RDBMSs: SQLite, MySQL, and PostgreSQL.
Read more >Getting Started with Sequelize and Postgres
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction ...
Read more >Battle of the Node.js ORMs: Objection vs. Prisma vs. Sequelize
Which Node.js ORM is the best tool for your backend project? Weigh the pros and cons of Objection, Prisma, and Sequelize and choose...
Read more >Behaviour of Bulk Insert in pgsql or any Database
Your statement runs in a transaction. If there is not already a transaction open, a transaction is created just for this statement and ......
Read more >Speeding up your development environment with SQLite
SQLite is a self-contained SQL database engine that significantly ... used alongside other relational databases like PostgreSQL, with SQLite ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I haven’t found any docs which would state such behaviour, except docs for posgreSQL where it got option ‘returning’
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the “stale” label. 🙂