Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including pg-live-table with all npm packages installed. Try it out:

var pgLiveTable = require("pg-live-table")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

pg-live-table v1.2.2

Real time monitoring of Postgres database 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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free