New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sequelize-model-comments

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-model-comments

Add comments to your Sequelize models.

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

Sequelize Model Comments

Comments support for your sequelize models. Record the user who created the comment. When used along with sequelize-paper-trail, annotates revisions with a user supplied comment.

node-version npm-version David David

GitHub release GitHub tag GitHub commits npm-downloads

license

Table of Contents

Installation

npm install --save sequelize-model-comments

Note: the current test suite is very limited in coverage.

Usage

Sequelize Model Comments assumes that you have already set up your Sequelize connection, for example, like this:

var Sequelize = require('sequelize');
var sequelize = new Sequelize('database', 'username', 'password');

then adding Sequelize Model Comments is as easy as:

var ModelComments = require('sequelize-model-comments').init(sequelize, options);
ModelComments.defineModels({});

which loads the Model Comments library, and the defineModels() method sets up a Comments table.

Note: If you pass userModel option to init in order to enable user tracking, userModel should be setup before defineModels() is called.

Then for each model that you want to keep a model comments you simply add:

Model.enableModelComments();

Example

var Sequelize = require('sequelize');
var sequelize = new Sequelize('database', 'username', 'password');

var ModelComments = require('sequelize-model-comments').init(sequelize, options || {});
ModelComments.defineModels();

var Post = sequelize.define('Post', {
  title: Sequelize.STRING,
  content: Sequelize.STRING,
});

Post.enableModelComments();

User Tracking

There are 2 steps to enable user tracking, ie, recording the user who created a comment.

  • Enable user tracking by passing userModel option to init, with the name of the model which stores users in your application as the value.
var options = {
  /* ... */
  userModel: 'users',
};
  • Pass the id of the user who is responsible for a database operation to sequelize-model-comments by sequelize options.
Post.update({
  /* ... */
  comment: 'This attribute will be used to create a comment which annotates the revision'
}, {
  userId: user.id
}).then(() {
  /* ... */
});

Options

Model Comments supports various options that can be passed into the initialization. The following are the default options:

Default options

// Default options
var options = {
  commentModel: 'Comment',
  UUID: false,
  underscored: false,
  underscoredAttributes: false,
  defaultAttributes: {
    documentId: 'documentId',
    model: 'model'
  },
};

Options documentation

OptionTypeDefault ValueDescription
[debug]BooleanfalseEnables logging to the console.
[commentModel]String'CommentName of the model that keeps the comments.
[UUID]BooleanfalseThe [commentModel] has id attribute of type UUID for postgresql.
[underscored]BooleanfalseThe [commentModel] has 'createdAt' and 'updatedAt' attributes, by default, setting this option to true changes it to 'created_at' and 'updated_at'.
[underscoredAttributes]BooleanfalseThe [commentModel] has a [defaultAttribute] 'documentId' by default, setting this option to true changes it to 'document_id'.
[defaultAttributes]Object{ documentId: 'documentId', model: 'model' }
[userModel]StringName of the model that stores users in your.

Support

Please use:

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Added some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Author

© Lijo Antony@lijo_lijozom@gmail.com
Distributed under the MIT license. See LICENSE for more information.
https://github.com/lijoantony/sequelize-model-comments

Thanks

This project was inspired by and derived from:

Keywords

sequelize

FAQs

Package last updated on 22 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts