question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

queryInterface.bulkInsert behaviour in SQLite / MySQL / PostreSQL is different

See original GitHub issue

What 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:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
eugene-matvejevcommented, Jul 25, 2019

id should be last or/and first for every dialect

Is this stated in the docs somewhere? (Just asking to label this correctly, depending on the response it’s bug/feature. Thanks!)

I haven’t found any docs which would state such behaviour, except docs for posgreSQL where it got option ‘returning’

0reactions
github-actions[bot]commented, Nov 9, 2021

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. 🙂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found