Sequelize how to check if entry exists in database

后端 未结 5 598
伪装坚强ぢ
伪装坚强ぢ 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:11

    You can count and find.

        Project
      .findAndCountAll({
         where: {
            title: {
              [Op.like]: 'foo%'
            }
         },
         offset: 10,
         limit: 2
      })
      .then(result => {
        console.log(result.count);
        console.log(result.rows);
      });
    

    Doc link, v5 Beta Release

提交回复
热议问题