npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sequelize-tracker

v1.1.3

Published

Track your models. Who creates, deletes, views and changes data.

Downloads

20

Readme

Sequelize Tracker

Track changes to your models. See who has looked at or changed the models data and how it was changed.

Build Status

Installation

npm install sequelize-tracker

How to use

1) Import sequelize-tracker

var Sequelize = require('sequelize');
var Tracker = require('sequelize-tracker');

Create a sequelize instance and your models, e.g.

var sequelize = new Sequelize('', '', '', {
  dialect: 'postgres'
});

2) Add the tracker feature to your models

var Target = sequelize.define('Target', attributes, options);

Tracker(Target, sequelize, options);

3) Use it in your queries

All create, update and destroy queries are logged by default. You just need to pass trackOptions object with user_id in options.

  model.create(data, {
    trackOptions: {
      user_id: // users id
    }
  })

update can be set to ignore changes by passing track: false in trackOptions.

  model.update(data, {
    trackOptions: {
      track: false
    }
  })

By default find does not logged. You will need explicitly to pass track: true in trackOptions.

  model.findAll({
    trackOptions: {
      track: true,
      user_id: // users id
    }
  })

Only update has a bulk update trigger. If you want to log other bulk operations. Use individualHooks: true.

By default there will be no user metadata saved. If you want to log this, pass all metadata information you want to metadata in trackOptions.

  model.create(data, {
    trackOptions: {
      user_id: // users id,
      metadata: // metadata object
    }
  })
Note:

Sequelize doesn't do deep equal checks. This means that when using instance.save(), the changed isn't triggered on fields that are data type JSON or Array. You have to use the setter set.

http://docs.sequelizejs.com/class/lib/model.js~Model.html#instance-method-set

Alternatively you can use model.update() which uses set internally.

4) How it is logged

Tracker creates a table and a model. Model is affixed with Log and table is affixed with Logs.

Table fields:

| changes | metadata | action | timestamp | user_id | target_id | | :-----------------------: |:-------------:| :-----: |:---------:|:----------:|:----------:| | Array<Object> || null | Object | String | Date | Integer | Integer |

Changes object example:

[{
  field: 'name',
  value: 'John',
  previousValue: 'Michael'
}]

Action is find, create, update or delete.

Options

The default syntax for Tracker is:

Tracker(model, sequelizeInstance, options)

whereas the options are listed here (with default value).

{
  // By default it keeps all logs after tracked item is deleted
  persistant: true,
  changes: ['update']
}

Only ['update', 'create', 'delete'] are supported. update cannot be excluded.

License

The MIT License (MIT)

Copyright (c) 2018 Sergei Liski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.