GitXplorerGitXplorer
k

postgres-triggers

public
8 stars
5 forks
1 issues

Commits

List of commits on branch master.
Unverified
e0c0d532299294a325e4e5027c637105241c69d3

0.2.0

kklaemo committed 10 years ago
Unverified
5e316040ae5b4011b7ade51bdf4925066d4a4968

support varying id types

kklaemo committed 10 years ago
Unverified
5470e0a44dc3630e7bd2236d73b6624d1748234f

let user specify the id column

kklaemo committed 10 years ago
Unverified
fc61a0c4016fb202b7a56a278ea1560ab60ec439

fix travis

kklaemo committed 10 years ago
Unverified
b39d8380385ba5af2117286d22599fc39699949c

add travis

kklaemo committed 10 years ago
Unverified
60fcfac42eec98852f2c40172cd84638a43489eb

0.1.4

kklaemo committed 10 years ago

README

The README file for this repository.

postgres-triggers Build Status

NPM

Create trigger functions for changes (INSERT, UPDATE, DELETE) in tables. The triggers will return a JSON object with some information and the changed row.

Heavily inspired by this blog post by @fritzy.

Because of the use of json_build_object() you'll need Postgres 9.4 or higher.

This module is in its early stages. Feedback and PRs welcome!

Install

npm i [-g] postgres-triggers

Usage (CLI)

postgres-triggers postgres://foo@localhost:5432/db table1 tbl2Name:idColumn ...

Usage (API)

const triggers = require('postgres-triggers')

triggers({
    db: 'postgres://foo@localhost:5432/db',
    // three ways of specifying table name and id column
    // default idColumn: 'id'
    tables: [
      'tbl1', 'tblName:idColumn', { name: 'tableName', id: 'idColumn'}
    ],
    channel: 'table_update' // optional
}, function(err) {
  if (err) throw err
  console.log('done')
})

Trigger Payload

{
  table: 'table-name',
  id: 'id-of-the-change-row',
  type: 'insert|update|delete',
  row: { id: 'baz', foo: 'bar', ... }
}

TODO

  • allow removal of triggers

Tests

You need to give it a database connection string to be able to run the tests.

POSTGRES=postgres://postgres@localhost:5432/postgres npm test

License

MIT