Sequelize how to check if entry exists in database

后端 未结 5 584
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 15:33

I need to check if entry with specific ID exists in the database using Sequelize in Node.js

  function isIdUnique (id) {
    db.Profile.count({ where: { id:          


        
5条回答
  •  甜味超标
    2021-01-01 16:19

    I found the answer by @alecxe to be unreliable in some instances, so I tweaked the logic:

    function isIdUnique (id, done) {
      db.Profile.count({ where: { id: id } })
      .then(count => {
        return (count > 0) ? true : false
      });
    }
    

提交回复
热议问题