sequelize-extension-deletedby
v0.0.7
Published
This extension will automatically add options.user.id to deletedBy when an instance is destroyed.
Downloads
21
Maintainers
Readme
sequelize-extension-deletedBy
Installation
$ npm install --save sequelize-extension-deletedBy
Usage
This library uses sequelize-extension to extend sequelize models. If a model has a deletedBy
field, this extension will automatically set deletedBy
to options.user.id
when an instance is destroyed.
const Sequelize = require('sequelize');
const extendSequelize = require('sequelize-extension');
const enhanceDeletedBy = require('sequelize-extension-deletedBy');
const sequelize = new Sequelize(...);
const Task = sequelize.define('task', {
name: Sequelize.STRING(255),
});
extendSequelize([Task], {
deletedBy: enhanceDeletedBy(),
});
// ...
await task.destroy({ user: { id: 2 } });
console.log(task1.deletedBy);
// 2
await task.destroy();
console.log(task1.deletedBy);
// 1 <- default userId
await db.Task.destroy({
where: {...},
user: { id: 3 },
});
// All destroyed instances will have deletedBy === 3
Other Extensions
sequelize-extension-tracking - Automatically track sequelize instance updates.
sequelize-extension-updatedby - Automatically set updatedBy
with options.user.id
option.
sequelize-extension-createdby - Automatically set createdBy
with options.user.id
option.
sequelize-extension-graphql - Create GraphQL schema based on sequelize models.
sequelize-extension-view - Models with the method createViews
will be called to create table views (virtual models).