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

sails-util-cold

v0.0.10

Published

Create a cold copy of models, for data consistency. Quite like event sourcing.

Downloads

4

Readme

sails-util-cold

You have to install it in the project where you want your models to be coldified.

How to use it

As this module tries to be compatible with all ways of injecting models in sails, including mvcsloader, you have to tell it to coldify models :

var cold = require('sails-util-cold')(sails);
cold.cold(__dirname + '/api/models');

Your models must have a cold property set to true if you want them to be coldified.

What does it do

Coldify content

Cold creates cold copies of your contents, in order to keep track of every modification applied to it. This is an alternative to Event sourcing like described my Martin Fowler.

This way, you have 2 main versions of every piece of content : the "hot" one, and the "cold" ones, that you don't need to worry about.

The "hot" model is still named after your model (ie. MyModel) and the cold copy is named "Cold" (ie. MyModelCold).

Link cold contents to cold contents

Furthermore, Cold also doubles every relational attributes of your models. The relation, of type collection (many-to-many or one-to-many) or model (one-to-one), is kept as the original, pointing to the hot model from the cold one.

But Cold will create the same relational attribute "coldified", pointing to the cold instance of the pointed model if it exists.

Example : If model "Pet" has a relation to "Human" via "Owner" attribute, "PetCold" will have "Owner" attribute linking to "Human" model and "OwnerCold" attribute linking to "HumanCold" model.

Benefits

Every time you update a content (an instance of a model, let's say the dog "Pluto", instance of "Pet" model), Cold creates a cold copy of Pluto, so you have 2 instances of "PetCold" : the original one and the new one.

Time 0 :

Pet

ID | Name | Toy --- | --- | --- 1 | Pluto | Ball

PetCold

ID | Name | Toy | coldReference --- | --- | --- | --- 1 | Pluto | Ball | 1

Time 1 : We change Pluto's toy, he prefers now shoe

Pet

ID | Name | Toy --- | --- | --- 1 | Pluto | Shoe

PetCold

ID | Name | Toy | coldReference --- | --- | --- | --- 1 | Pluto | Ball | 1 2 | Pluto | Shoe | 1

Use it with caution !

Even if Cold tried to be the lightest possible, it is a huge amount of data that will be added to your database. Use it only if you absolutely need it on production environments, and don't set "cold" property on models that don't need it.

Todo

  • Add a cold property on attributes, to specify if they have to be copied in cold copy of the model
  • Add sails-specific cold methods like findCold and so on