sequelize-soft-delete
v1.1.0
Published
Sequelize model plugin for add soft-delete method
Downloads
305
Readme
sequelize-soft-delete
Sequelize model plugin for add soft-delete method
Installation
npm i sequelize-soft-delete
Use
// model.js
const sequelizeSoftDelete = require('sequelize-soft-delete')
module.exports = (sequelize, DataTypes) => {
const MyModel = sequelize.define(
'MyModel',
{
deleted: {
type: DataTypes.INTEGER(1),
defaultValue: 0
}
},
{
defaultScope: {
where: {
deleted: 0
}
}
}
)
const options = {field: 'deleted', deleted: 1}
sequelizeSoftDelete.softDelete(MyModel, options)
return MyModel
}
// controller.js
const updated = await db.MyModel.softDelete({ where: { id: 1 } })