// 增
user.create({id, name, age});
user.create({id, name, age}, {transaction: t});
// 删
user.destroy({where: {id}});
user.destroy({where: {id}, transaction: t});
// 改
user.update({age: 30}, {where: {id}});
user.update({age: 30}, {where: {id}, transaction: t});
// 查
user.findOne({
where: {id},
attributes: ['id', 'name', 'age'],
raw: true,
transaction:t
});
user.findByPk(id, {attributes: ['id', 'name', 'age'], transaction:t});
user.findAll({
where: {id},
attributes: ['id', 'name', 'age'],
raw: true,
transaction:t
});
user.findAndCountAll({
where: {id},
attributes: ['id', 'name', 'age'],
raw: true,
transaction:t
});
user.count({
where:{age,id,name}
})
// 查改
user.findOrCreate({
where:{id,age,name}
})
nodejs sequlize 的基础增删改查的常用api
于 2024-01-30 07:22:39 首次发布