这是我在mysql中的查询
我想在sequelize orm中使用此查询
SELECT
`uid`,
`username`
FROM
`users` AS `users`
WHERE
BINARY
`users`.`username` IN ('hammad', 'sAad')
AND `users`.`status` = 'ACTIVE'
ORDER BY
FIELD(
`username`,
'hammad',
'saad.ahmed'
)
LIMIT 20;
我想要续集查询
答案 0 :(得分:0)
UserModel.findAll({
attributes: ['uid', 'username'],
where : {
username : {
[Op.in]: [ 'hammad' , 'sAad']
},
status : 'active'
},
order : ['username']
});
答案 1 :(得分:0)
这是在条件
中查找区分大小写的解决方案db.models.users.findAll({
attributes: ['uid', 'username'],
where: {
username: db.sequelize.where(
db.sequelize.literal('BINARY username IN ('),
`'${users.join("', '")}'`,
db.sequelize.literal(')'),
),
status: 'ACTIVE'
},
order: !_.isEmpty(users) ? [[db.sequelize.fn('FIELD', db.sequelize.col('username'), ...users)]] : [],
limit: 20
});
答案 2 :(得分:0)
[Op.and]: where(fn('binary', col('username')), { [Op.in]: ['xxx','xxx2'] })