Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eclass/sequelize-soft-delete

Sequelize model plugin for add soft-delete method
https://github.com/eclass/sequelize-soft-delete

Last synced: about 1 month ago
JSON representation

Sequelize model plugin for add soft-delete method

Awesome Lists containing this project

README

        

# sequelize-soft-delete

[![npm version](https://img.shields.io/npm/v/sequelize-soft-delete.svg?style=flat-square)](https://www.npmjs.com/package/sequelize-soft-delete)
[![npm downloads](https://img.shields.io/npm/dm/sequelize-soft-delete.svg?style=flat-square)](https://www.npmjs.com/package/sequelize-soft-delete)
[![devDependency Status](https://img.shields.io/david/dev/eclass/sequelize-soft-delete.svg?style=flat-square)](https://david-dm.org/eclass/sequelize-soft-delete#info=devDependencies)

> Sequelize model plugin for add soft-delete method

## Installation

```bash
npm i sequelize-soft-delete
```

## Use

```js
// 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 } })
```

## License

[MIT](https://tldrlegal.com/license/mit-license)