How to convert entity to plain object with Sequelize?

Sometimes, we want to convert entity to plain object with Sequelize.

In this article, we’ll look at how to convert entity to plain object with Sequelize.

How to convert entity to plain object with Sequelize?

To convert entity to plain object with Sequelize, we can call findAll with raw and nest set to true.

For instance, we write

db.Sensors.findAll({
  where: {
    nodeid
  },
  raw: true,
  nest: true,
})

to call findAll with an object with a where property to find the item with the given nodeid value.

And we set raw to true to return the result as a plain object.

We set nest to true to prevent nesting of associations.

Conclusion

To convert entity to plain object with Sequelize, we can call findAll with raw and nest set to true.