How to see the SQL generated by Sequelize.js?

Sometimes, we want to see the SQL generated by Sequelize.js.

In this article, we’ll look at how to see the SQL generated by Sequelize.js.

How to see the SQL generated by Sequelize.js?

To see the SQL generated by Sequelize.js, we can use the sequelize.sync method or set the logging option when we create our Sequelize instance.

For instance, we write

const sequelize = new Sequelize('database', 'username', 'password', {
  logging: console.log
});

to connect to our database by creating a Sequelize instance with the 'database' name, 'username' and 'password'.

We log the SQL code generated by Sequelize by setting logging to console.log.

Also, we can use sequelize.sync by writing

sequelize.sync({
  logging: console.log
})

to let us log the generated SQL in the console.

Conclusion

To see the SQL generated by Sequelize.js, we can use the sequelize.sync method or set the logging option when we create our Sequelize instance.