{"_id":"strong-db-watcher","_rev":"64-fdc011dcf7892c2b7bb78fc2fa0ebd54","name":"strong-db-watcher","dist-tags":{"latest":"1.2.1"},"versions":{"1.2.0":{"name":"strong-db-watcher","version":"1.2.0","author":{"name":"Tetsuo Seto","email":"seto@strongloop.com"},"license":"Artistic-2.0","_id":"strong-db-watcher@1.2.0","maintainers":[{"name":"setogit","email":"setogit@gmail.com"}],"homepage":"https://github.com/strongloop/strong-db-watcher","bugs":{"url":"https://github.com/strongloop/strong-db-watcher/issues"},"dist":{"shasum":"449684d55b63f707c88cdf6c0e3be38ea6afeeea","tarball":"https://registry.npmjs.org/strong-db-watcher/-/strong-db-watcher-1.2.0.tgz","integrity":"sha512-59OLCBUKoqf2CsLJ1+XTwJUFIkyFLxWYRkCDGmd6IfYeiKxiKXeW/MhJIcvSOdzz7meez9UuJno5LmHrsoTw1g==","signatures":[{"sig":"MEQCIAa8tQKO9Vr95oSvAS3HWq37TCCtAkaYTVKYykm+DNPzAiBgqBS0JhcJ3wgy4snyHxdQQvp+TBKtL9chQnMPKJC8sQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"449684d55b63f707c88cdf6c0e3be38ea6afeeea","gitHead":"b6b55facb6c3ca67871811e4a1edab805c2ea13a","scripts":{"test":"tap --bail --coverage --coverage-report=cobertura --timeout=200 test/test-*.*","pretest":"eslint --ignore-path .gitignore . && jscs ./","posttest":"nyc report --reporter=lcov && nyc report"},"_npmUser":{"name":"setogit","email":"setogit@gmail.com"},"repository":{"url":"git://github.com/strongloop/strong-db-watcher.git","type":"git"},"_npmVersion":"2.11.3","description":"Database Watch/Broadcast Notification","directories":{},"_nodeVersion":"0.12.7","dependencies":{"async":"^1.4.2","debug":"^2.2.0"},"devDependencies":{"pg":"^4.4.1","nyc":"^3.1.0","tap":"^1.3.4","jscs":"^2.1.1","eslint":"^1.3.1"}},"1.2.1":{"name":"strong-db-watcher","version":"1.2.1","author":{"name":"Tetsuo Seto","email":"seto@strongloop.com"},"license":"Artistic-2.0","_id":"strong-db-watcher@1.2.1","maintainers":[{"name":"bajtos","email":"mbajtoss@gmail.com"},{"name":"chandadharap","email":"chanda_dharap@yahoo.com"},{"name":"ibmcloud-admin","email":"rmg@ca.ibm.com"},{"name":"kraman","email":"kraman@gmail.com"},{"name":"octet","email":"vieuxtech@gmail.com"},{"name":"rfeng","email":"enjoyjava@gmail.com"},{"name":"ritch","email":"skawful@gmail.com"},{"name":"rmg","email":"r.m.graham@gmail.com"},{"name":"strongloop","email":"strngops@us.ibm.com"}],"homepage":"https://github.com/strongloop/strong-db-watcher","bugs":{"url":"https://github.com/strongloop/strong-db-watcher/issues"},"dist":{"shasum":"be5fe480825a81cef176e4724628dac5bf153122","tarball":"https://registry.npmjs.org/strong-db-watcher/-/strong-db-watcher-1.2.1.tgz","integrity":"sha512-s3/EVt/jD/aURvAPRUVbE8BFkoUiG5VqbphUx8W6/E27TxVHvwVYnlsoRlBKFj1TH5qFQV1m3f9Q+h+qmGAX/Q==","signatures":[{"sig":"MEUCIQD9NuwaSJhbqNnJkqQFm8f8jyigUAHQLi1HI57NKxwVEQIgBxg0po2yOhZeqDrLoaiWDRoqkhmAEuUxBbSkdzxmZbo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"be5fe480825a81cef176e4724628dac5bf153122","gitHead":"e584b38d57bb820c10e682f80b9c9bae9b214be8","scripts":{"test":"tap --bail --coverage --coverage-report=cobertura --timeout=200 test/test-*.*","pretest":"eslint --ignore-path .gitignore . && jscs ./","posttest":"nyc report --reporter=lcov && nyc report"},"_npmUser":{"name":"rmg","email":"r.m.graham@gmail.com"},"repository":{"url":"git://github.com/strongloop/strong-db-watcher.git","type":"git"},"_npmVersion":"3.8.8","description":"Database Watch/Broadcast Notification","directories":{},"_nodeVersion":"4.4.3","dependencies":{"async":"^1.4.2","debug":"^2.2.0"},"devDependencies":{"pg":"^4.4.1","nyc":"^3.1.0","tap":"^1.3.4","jscs":"^2.1.1","eslint":"^1.3.1"},"_npmOperationalInternal":{"tmp":"tmp/strong-db-watcher-1.2.1.tgz_1462577588304_0.35748521401546896","host":"packages-16-east.internal.npmjs.com"}}},"time":{"created":"2015-09-28T20:30:24.181Z","modified":"2026-04-14T15:10:40.910Z","1.2.0":"2015-09-28T20:30:24.181Z","1.2.1":"2016-05-06T23:33:11.187Z"},"bugs":{"url":"https://github.com/strongloop/strong-db-watcher/issues"},"author":{"name":"Tetsuo Seto","email":"seto@strongloop.com"},"license":"Artistic-2.0","homepage":"https://github.com/strongloop/strong-db-watcher","repository":{"url":"git://github.com/strongloop/strong-db-watcher.git","type":"git"},"description":"Database Watch/Broadcast Notification","maintainers":[],"readme":"# strong-db-watcher\n\nEvent broadcast/watch mechanism triggered by internal database events\nsuch as Create, Update or Delete.\n\n## DbWatcher: Class, inherits EventEmitter\n\n- `dbClient` a postgres handle already connected to the DB\n- `changeListener` {Function} called at every watched event with (result) where,\n    - result: {Object}\n      - `table` {String} table name\n      - `op` {String} `INSERT`, `UPDATE`, `INSERTorUPDATE`, or `DELETE`\n      - `when` {String} `BEFORE`, `AFTER`, or `UNSPECIFIED`\n      - `payload`{Object} database record\n      - `receivedAt` {Integer} timestamp in msec since the epoch\n         when the broadcast msg is received by the watcher,\n         not when the broadcast event is generated by the broadcaster.\n\n    Event is emitted per each table with result {Object}.\n    In case changeListener is set, it's called for every event\n    in addition to event.  Usage below shows how to watch events.\n\n### watchTable\n\n- `name` {String} table name\n- `callback` {Function} called with err\n\n### isWatching\n\nreturns {Boolean}\n\n- `name` {String} table name\n- `fn` {Function} listener function\n\n### unwatchTable\n\nunwatch one table\n\n- `name` {String} table name,\n- `callback` {Function} called with err\n\n### close\n\nunwatch all the watching tables\n\n- `callback` {Function} called with err\n\n## Usage: notified by changeListener\n\n```\n    var pg = require('pg');\n    var DbWatcher = require('strong-db-watcher');\n    var tableName = 'serviceinstance';\n\n    var client = new pg.Client(<connection string>);\n    client.connect(function(err) {\n      var sdw = new DbWatcher(client,\n        function(result) {\n          ... all events are watched ...\n          ... switch (result.table) case to ...\n          ... process all events here or emit your own event ...\n        });\n    sdw.watchTable(name, function(err) {\n      console.log('watchTable error');\n    });\n```\n\n## Usage: notified by Events\n\n```\n    var pg = require('pg');\n    var DbWatcher = require('strong-db-watcher');\n    var tableName = 'serviceinstance';\n\n    var client = new pg.Client(<connection string>);\n    client.connect(function(err) {\n      var sdw = new DbWatcher(client);\n      sdw.on(name,\n        function(result) {\n          ... process the result here ...\n          ... events for the table only ...\n        });\n    sdw.watchTable(name, function(err) {\n      console.log('watchTable error');\n    });\n```\n\n## Result:\n\n```\n\t{\n\t  table: 'serviceinstance',\n\t  op: 'UPDATE',\n\t  when: 'BEFORE',\n\t  payload:\n\t    {\n\t      executorid: 155,\n\t      serverserviceid: 1,\n\t      groupid: 1,\n\t      currentdeploymentid: 'some commit',\n\t      containerversioninfo: {},\n\t      token: 'bc1357e132318ade13dd008a882d2d0fe5fb1980e7d98c0a',\n\t      started: false,\n\t      setsize: 0,\n\t      cpus: 'CPU',\n\t      tracingenabled: false,\n\t      id: 153\n\t    },\n\t  receivedAt: 1440828036502\n\t}\n```\n","readmeFilename":"README.md"}