Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

bookshelf-deep-changed-plugin

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf-deep-changed-plugin

Allows bookshelf models to check whether a value you save is different than the existing value in the database.

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
5
-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

bookshelf-deep-changed-plugin

NPM Version Build Status Test Coverage Dependencies devDependencies JavaScript Style Guide

Allows bookshelf models to check whether a value you save is different than the existing value in the database.

Installation:

$ npm install --save bookshelf-deep-changed-plugin

Usage:

module.exports = Repository.Model.extend({
  tableName: 'users',
  initialize: function () {
    this.on('updating', function (model, attrs, options) {
      return this
        .deepChanged('name', 'email', options)
        .then(function (hasDeepChanged) {
          if (hasDeepChanged[0]) {
            this.set('name_changed_at', new Date());
          }
          if (hasDeepChanged[1]) {
            this.set('email_changed_at', new Date());
          }
        });
    });
  }
});

Do not forget to add bookshelf-deep-changed-plugin to the list of bookshelf's plugins when you require bookshelf:

const knex = require('knex')({
    /// knex initialization
  })
const bookshelf = require('bookshelf')(knex);

bookshelf.plugin(require('bookshelf-deep-changed-plugin'));

License

MIT

Author

Oron Nadiv (oron@nadiv.us)

Keywords

bookshelf

FAQs

Package last updated on 02 Jul 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