排序,检查行是否存在并返回布尔值

时间:2020-04-20 16:01:38

标签: node.js sequelize.js

请帮助

如何实现请求“ SELECT EXISTS(SELECT FROM FROM Followers WHERE follower_id = 100);”通过Sequelize并将结果显示在单独的字段中?

类似的东西

await Followers.findAll({
  where: { user_id: userId },
  include: [
     {
      model: Followers,
      as: 'isSubscribed',
      ...
      },
    },
  ]

1 个答案:

答案 0 :(得分:0)

做类似

let followersCount = Followers.count({ where: {follower_id: 100} })

if(followersCount > 0){
  //EXISTS, Do Something
}
else{
   //Does not exist
 }