0.1.1 • Published 7 years ago

sails-persistence-stream v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

Sails Persistence Stream

NPM

Automatically stream all Sails model persistence events to a distributed log

Install

npm install --save sails-persistence-stream

Use

To use Sails Persistence Stream out of the box add the streamer to config/models.js default persistence hooks so it looks like the following example:

var sailsPersistenceStream = require('sails-persistence-stream')();

module.exports.models = {
  afterCreate: function(record, cb) {
    sailsPersistenceStream.afterCreate(record, this).then(data => {
      cb();
    });
  },
  afterUpdate: function(record, cb) {
    sailsPersistenceStream.afterUpdate(record, this).then(data => {
      cb();
    });
  },
  afterDestroy: function(record, cb) {
    sailsPersistenceStream.afterDestroy(record, this).then(data => {
      cb();
    });
  }
};

API

require('sails-persistence-stream')(options: Object)

Initializes Sails Persistence Stream with the given options. All options are optional.

  • options.stream: Kinesis stream name (must exist already)
  • options.region: (default: us-east-1) AWS region
  • options.logger: Log4js compatible logger which Sails Persistence Stream will use (set to null for no logging)
  • options.endpoint: (Optional) Alternative Kinesis endpoint (for local testing use Kinesalite)