1const project = await Project.findOne({ where: { title: 'My Title' } });
2if (project === null) {
3 console.log('Not found!');
4} else {
5 console.log(project instanceof Project); // true
6 console.log(project.title); // 'My Title'
7}
8
1// Example
2const Tokens = db.define('tokens', {
3 guid: {
4 type: sequelize.STRING
5 }
6});
7// The basics of Sequelize Get Where
8Tokens.findAll({
9 where: { guid: 'guid12345' }
10 }).then(tokens => {
11 console.log(tokens);
12 }).catch(err => console.log('error: ' + err));;
13// is equal to >> SELECT * FROM Tokens WHERE guid = 'guid12345'
1 exports.getMinPrice = () => Item.findAll({ attributes: [[sequelize.fn('min', sequelize.col('price')), 'minPrice']], });