Automatically stream all Sails model persistence events to a distributed log
npm install --save sails-persistence-stream
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();
});
}
};
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 regionoptions.logger
: Log4js compatible logger which Sails Persistence Stream will use (set tonull
for no logging)options.endpoint
: (Optional) Alternative Kinesis endpoint (for local testing use Kinesalite)