Categories
JavaScript Answers

How to specify specific fields with Node Sequelize instead of *?

Spread the love

To specify specific fields with Node Sequelize instead of *, we set the attributes property.

For instance, we write

const list = await template.findAll({
  where: {
    user_id: req.params.userId,
  },
  attributes: ["id", "template_name"],
});
res.status(200).json(list);

to call findAll with an object with the attributes property set to an array of columns to select.

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 *