node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

pg-live-table

pg-live-table: Postgres live monitoring

A javascript library to monitor in real time Postgresql database table.

Build Status Code Climate Coverage Status NPM version

Dependency Status

Install

$ npm install --save pg-live-table

Usage

import PgLiveTable from 'pg-live-table';
 
let dbUrl = 'postgres://username:password@localhost/database';
let liveTable = PgLiveTable({dbUrl: dbUrl);
 
let ee = await liveTable.monitor('mytable');
ee.on('insert', (payload) => {
  console.log(`GOT insert: data: ${payload.data}`);
})
.on('update', (payload) => {
  let {old_data, new_data} = payload;
  console.log(`GOT update: old: ${old_data}, new: ${new_data}`);
})
.on('delete', (payload) => {
  console.log(`GOT delete: data: ${payload.data}`);
});
 
await liveTable.listen();
 
//When done, don't forget to call liveTable.close() 
 

Test

Make sure Postgres is running locally before running the test

$ npm test

License

MIT © Frederic Heem