1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
const users = await User.findAll(); const user = await User.findOne({ where: { id: userId } })
Model.findAll({ attributes: ['field1', 'field2', ['field3', 'new_field3'], [sequelize.fn('COUNT', sequelize.col('field4'), 'count_of_field4')], ], order: [ ['title', 'DESC'], ['name', 'ASC'], sequelize.fn('max', seque) ], group: 'name', limit: 10, offset: 10 });
const amount = await User.count({where: {...}}})
Model.findAll({ attributes: { include: [ [sequelize.fn('COUNT', sequelize.col('field4'), 'count_of_field4')] ] } });
Model.findAll({attributes: {exclude: ['field4']}});
const { Op } = require('sequelize'); User.findAll({ where: { name: 'abc', [Op.and]: [{status:1}, {id: 11}], [Op.or]: [{status:1}, {id: 11}], someAttribute: { {[Op.or]: [12, 13]}, [Op.ne]: 20, [Op.is]: null, [Op.not]: true, [Op.gt]: 6, [Op.gte]: 6, [Op.lt]: 10, [Op.lte]: 10, [Op.between]: [6, 10], [Op.notBetween]: [11, 15], [Op.in]: [1, 2], [1, 2, 3], [Op.notIn]: [1, 2], [Op.like]: '%hat', [Op.notLike
]: '%hat', [Op.startsWith]: 'hat', [Op.endsWith]: 'hat', [Op.substring]: 'hat', [Op.iLike]: '%hat', [Op.regexp]: '^[h|a|t]', [Op.notRegexp]: '^[h|a|t]', [Op.iRegexp]: '', [Op.notIRegexp]: '', [Op.any]: [2, 3], } });
|