Sequelize provides various methods to query data from your models, such as findAll, findOne, findByPk, findOrCreate, or count. These methods take an object as an argument, which can contain filters, attributes, order, limit, offset, include, or raw. The filters are the conditions that the data must match, such as where, or, and, or operators. The attributes are the columns that you want to select, or exclude. The order is the sorting criteria for the data, such as ascending or descending. The limit and offset are the pagination parameters for the data. The include is the option to eager load the associated models, or join them. The raw is the option to return plain objects instead of model instances. For example, to query all the posts that belong to a user with a given id, and include the user's name, you can write:
Post.findAll({
where: {
userId: id
},
attributes: ['title', 'content'],
order: [['createdAt', 'DESC']],
limit: 10,
include: {
model: User,
attributes: ['firstName', 'lastName']
},
raw: true
});