sequelize findone code example
Example 1: sequelize find one
const project = await Project.findOne({ where: { title: 'My Title' } });
if (project === null) {
console.log('Not found!');
} else {
console.log(project instanceof Project);
console.log(project.title);
}
Example 2: 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 3: sequelize max
exports.getMinPrice = () => Item.findAll({ attributes: [[sequelize.fn('min', sequelize.col('price')), 'minPrice']], });