Answers for "sequelize group by"

3

sequelize.fn

// Counting number of totalPrice from column itemPrice table 
Model.findAll({
  attributes: {
    include: [
      [sequelize.fn('COUNT', sequelize.col('itemPrice')), 'totalPrice']
    ]
  }
});
Posted by: Guest on December-24-2020
1

sequelize get where

// Example
const Tokens = db.define('tokens', {
    guid: {
        type: sequelize.STRING
    }
});
// The basics of Sequelize Get Where
Tokens.findAll({
        where: { guid: 'guid12345' }
    }).then(tokens => {
        console.log(tokens);
    }).catch(err => console.log('error: ' + err));;
// is equal to >> SELECT * FROM Tokens WHERE guid = 'guid12345'
Posted by: Guest on January-25-2021
2

sequelize .all()

yourTableModel.findAll({
  //optional filters
  where: {},
  raw: true,
})
Posted by: Guest on November-12-2020
0

sequelize group by

Project.findAll({ group: 'name' });
// yields 'GROUP BY name'
Posted by: Guest on August-18-2021

Browse Popular Code Answers by Language