Get only dataValues from Sequelize ORM

I'm using the sequelize ORM to fetch data from a PSQL DB. However, when I retrieve something, a whole bunch of data is given. The only data I want is inside 'dataValues'. Of course, I can use object.dataValues. But, is there any other good solutions?

I'm using Sequelize 4.10


Solution 1:

Yes you can

Model.findAll({
 raw: true,
 //Other parameters
});

would return just the data and not the model instance

Solution 2:

Sequelize wraps all it's return values in a virtual object that contains meta data. If you have an object and you just want the undecorated data values, you can unwrap them like so:

Model.findById(1).then(data => {
  console.log(data.get({ plain: true }));
});

Additionally if you just want to print out the object you can use the .toJSON method.

Model.findById(1).then(data => {
  console.log(data.toJSON());
});