Categories
JavaScript Answers

How to see the SQL generated by Sequelize.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *