美文网首页sequelize
Sequelize | 7. 模型 - 更新、删除数据

Sequelize | 7. 模型 - 更新、删除数据

作者: ShadowFieldEric | 来源:发表于2021-01-17 19:46 被阅读0次

参考查询数据的所有条件筛选方法,即where相关的内容

更新数据

(async () => {
  await UserModel.update({
    last_name: 'Li'
  }, {
    where: { last_name: 'Lee' }
  });
  let users = await UserModel.findAll();
  console.log(JSON.stringify(users, null, 2));
})();

删除数据

(async () => {
  await UserModel.destroy({
    where: {
      id: 2
    }
  });
  let users = await UserModel.findAll();
  console.log(JSON.stringify(users, null, 2));
})();

相关文章

网友评论

    本文标题:Sequelize | 7. 模型 - 更新、删除数据

    本文链接:https://www.haomeiwen.com/subject/injyoktx.html