Get only dataValues from Sequelize ORM
Finally I found answer after searching a lot. you should do something like this
const users = await db.users.findAll({})
.map(el => el.get({ plain: true })) // add this line to code
source: github issue
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());
});
Yes you can
Model.findAll({
raw: true,
//Other parameters
});
would return just the data and not the model instance