Postgres pub/sub
npm install pg-dispatch
psql -h localhost -d mydb < install.sql
var dispatcher = require('pg-dispatch')({
// client: ... // pg client can be passed or
conString: '', // same as for pg driver
// Default options:
// changesChannel: 'data_changes',
// names: {
// notifyTrigger: 'data_change_notify_trigger',
// notifyTriggerFunc: 'data_change_notify_trigger_func',
// addNotifyTrigger: 'add_notify_trigger_to_table',
// removeNotifyTrigger: 'remove_notify_trigger_to_table'
// },
// operationEvents: true, // false to NOT send events on each operation
// checkUpdates: true // only notify if update changes record
// sendRecordId: false // send only record IDs, true - to send column 'id',
// string to send column with a given name.
// this column should be a number.
// by default the whole record data is sent.
});
dispatcher.install(function(err) {
if (err) return console.log(err);
dispatcher.subscribe('users', function(error, data) {
if(error) throw error;
console.log('Subscribed:' data);
});
});
dispatcher.on('users:insert', function (error, data) {
if (error) throw error;
console.log(data);
});
MIT