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

@invisible/sequelize-temporal

v1.1.2

Published

Temporal tables for Sequelize

Downloads

8

Readme

Temporal tables for Sequelize

(aka "Historical records")

Build Status Dependency Status NPM version

Forked from: https://github.com/bonaval/sequelize-temporal

What is it?

Temporal tables maintain historical versions of data. Modifying operations (UPDATE, DELETE) on these tables don't cause permanent changes to entries, but create new versions of them. Hence this might be used to:

  • log changes (security/auditing)
  • undo functionalities
  • track interactions (customer support)

Under the hood a history table with the same structure, but without constraints is created.

The normal singular/plural naming scheme in Sequelize is used:

  • model name: modelName + History
  • table name: modelName + Histories

Installation

npm install sequelize-temporal

How to use

1) Import sequelize-temporal

var Sequelize = require('sequelize');
var Temporal = require('sequelize-temporal');

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

var sequelize = new Sequelize('', '', '', {
	dialect: 'sqlite',
	storage: __dirname + '/.test.sqlite'
});

2) Add the temporal feature to your models

var User = Temporal(sequelize.define('User'), sequelize);

The output of temporal is its input model, so assigning it's output to your Model is not necessary, hence it's just the lazy version of:

var User = sequelize.define('User', {.types.}, {.options.}); // Sequelize Docu
Temporal(User, sequelize);

Options

The default syntax for Temporal is:

Temporal(model, sequelizeInstance, options)

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

{
  /* runs the insert within the sequelize hook chain, disable
  for increased performance without warranties */
  blocking: true,
  /* By default sequelize-temporal persist only changes, and saves the previous state in the history table.
  The "full" option saves all transactions into the temporal database
  (i.e. this includes the latest state.)
   This allows to only query the hostory table to get the full history of an entity.
  */
  full: false

Details

@See: https://wiki.postgresql.org/wiki/SQL2011Temporal

History table

History table stores historical versions of rows, which are inserted by triggers on every modifying operation executed on current table. It has the same structure and indexes as current table, but it doesn’t have any constraints. History tables are insert only and creator should prevent other users from executing updates or deletes by correct user rights settings. Otherwise the history can be violated.

Hooks

Triggers for storing old versions of rows to history table are inspired by referential integrity triggers. They are fired for each row before UPDATE and DELETE (within the same transaction)

Notes

If you only use Postgres, you might want to have a look at the Temporal Table extension.

License

The MIT License (MIT)

Copyright (c) 2015 BonaVal

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.