sequelize get all records code example
Example 1: sequelize get where
const Tokens = db.define('tokens', {
guid: {
type: sequelize.STRING
}
});
Tokens.findAll({
where: { guid: 'guid12345' }
}).then(tokens => {
console.log(tokens);
}).catch(err => console.log('error: ' + err));;
Example 2: sequelize .all()
yourTableModel.findAll({
where: {},
raw: true,
})
Example 3: sequelize max
exports.getMinPrice = () => Item.findAll({ attributes: [[sequelize.fn('min', sequelize.col('price')), 'minPrice']], });
Example 4: sequelize count all
Project.count().then(c => {
console.log("There are " + c + " projects!")
})
Project.count({ where: {'id': {[Op.gt]: 25}} }).then(c => {
console.log("There are " + c + " projects with an id greater than 25.")
})