bookshelf-deep-changed

1.0.0 • Public • Published

Dependencies devDependency Status Build Status

bookshelf-deep-changed

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

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());
          }
        });
    });
  }
});

You need to add bookshelf-deep-changed to the list of bookshelf's plugins when you require bookshelf:

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

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

/bookshelf-deep-changed/

    Package Sidebar

    Install

    npm i bookshelf-deep-changed

    Weekly Downloads

    26

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • rahulbharadwaj
    • jasif-wm
    • shyam.mohan
    • qbibrahim
    • sidharth.n
    • hariqb
    • arjuncprasannan
    • renjith_ram_qburst
    • anasqburst
    • jyothis-qb
    • qburst-pratyush
    • cdrohithmqb
    • sudheeshqburst
    • davoodul
    • mable-liza-mathew
    • sowmyab
    • anoop-kuttikkattu
    • munisa
    • dheerajds
    • arjunqb
    • ashishqburst
    • lanetix-system
    • manu-kodiyan-winmore
    • dnm-winmore
    • mkdyanugk
    • vigneshk7
    • soumyaarun
    • aswanth
    • sajith.qb
    • dhiluraj-qburst
    • anandqb
    • arun-dtk
    • vikasqb
    • acpradosh1234