Compare commits

..

No commits in common. "master" and "development" have entirely different histories.

5 changed files with 14 additions and 208 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
node_modules/

View File

@ -60,9 +60,4 @@ The node will produce a message like that :
{"name":"notification","length":47,"processId":16147,"channel":"addedrecord","payload":{"id":2,"title":"plopcsd"}}
All fields are generated by Postgres with *payload* being the content of the table row.
Changelog
---------
- 0.2.0 : Removed the postgres configuration Node and created a dependency to https://flows.nodered.org/node/node-red-contrib-postgres making it possible to have both nodes installed.
All fields are generated by Postgres with *payload* being the content of the table row.

181
package-lock.json generated
View File

@ -1,181 +0,0 @@
{
"name": "node-red-contrib-postgres-listen",
"version": "0.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw=="
},
"lodash": {
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
},
"node-postgres-named": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/node-postgres-named/-/node-postgres-named-2.4.1.tgz",
"integrity": "sha1-GgfQZjaI2V48wQVy04xfUOJyIsk=",
"requires": {
"lodash": "^4.0.0"
}
},
"node-red-contrib-re-postgres": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/node-red-contrib-re-postgres/-/node-red-contrib-re-postgres-0.2.2.tgz",
"integrity": "sha512-fJJSTDqN1a052dwtNlxEVKDK1BUzcUPCnKg0mSZL4//NX54W14go9ai12sZSUTamicrtlOls4CXqW0C4vp3toA==",
"requires": {
"node-postgres-named": "^2.4.1",
"pg": "^7.18.2",
"pg-cursor": "^2.1.6"
},
"dependencies": {
"pg": {
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/pg/-/pg-7.18.2.tgz",
"integrity": "sha512-Mvt0dGYMwvEADNKy5PMQGlzPudKcKKzJds/VbOeZJpb6f/pI3mmoXX0JksPgI3l3JPP/2Apq7F36O63J7mgveA==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "0.1.3",
"pg-packet-stream": "^1.1.0",
"pg-pool": "^2.0.10",
"pg-types": "^2.1.0",
"pgpass": "1.x",
"semver": "4.3.2"
}
}
}
},
"packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"pg": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.3.0.tgz",
"integrity": "sha512-jQPKWHWxbI09s/Z9aUvoTbvGgoj98AU7FDCcQ7kdejupn/TcNpx56v2gaOTzXkzOajmOEJEdi9eTh9cA2RVAjQ==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.3.0",
"pg-pool": "^3.2.1",
"pg-protocol": "^1.2.5",
"pg-types": "^2.1.0",
"pgpass": "1.x",
"semver": "4.3.2"
},
"dependencies": {
"pg-connection-string": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.3.0.tgz",
"integrity": "sha512-ukMTJXLI7/hZIwTW7hGMZJ0Lj0S2XQBCJ4Shv4y1zgQ/vqVea+FLhzywvPj0ujSuofu+yA4MYHGZPTsgjBgJ+w=="
},
"pg-pool": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.2.1.tgz",
"integrity": "sha512-BQDPWUeKenVrMMDN9opfns/kZo4lxmSWhIqo+cSAF7+lfi9ZclQbr9vfnlNaPr8wYF3UYjm5X0yPAhbcgqNOdA=="
}
}
},
"pg-connection-string": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz",
"integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc="
},
"pg-cursor": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pg-cursor/-/pg-cursor-2.3.0.tgz",
"integrity": "sha512-9vOHIWz8T3BWDfif7CDeZVjXUhRv4qOz/FDxolNBBU6AYgK2GThxOYsY6vmNJWuA61rtRrpAorO+LyX9X3o/4A=="
},
"pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-packet-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz",
"integrity": "sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg=="
},
"pg-pool": {
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.10.tgz",
"integrity": "sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg=="
},
"pg-protocol": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.2.5.tgz",
"integrity": "sha512-1uYCckkuTfzz/FCefvavRywkowa6M5FohNMF5OjKrqo9PSR8gYc8poVmwwYQaBxhmQdBjhtP514eXy9/Us2xKg=="
},
"pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
}
},
"pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"requires": {
"split": "^1.0.0"
}
},
"postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.6.tgz",
"integrity": "sha512-o2a4gxeFcox+CgB3Ig/kNHBP23PiEXHCXx7pcIIsvzoNz4qv+lKTyiSkjOXIMNUl12MO/mOYl2K6wR9X5K6Plg=="
},
"postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"requires": {
"xtend": "^4.0.0"
}
},
"semver": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
},
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"requires": {
"through": "2"
}
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
}
}
}

View File

@ -1,10 +1,10 @@
{
"name": "node-red-contrib-postgres-listen",
"version": "0.3.0",
"version": "0.2.0",
"description": "A Node-RED node to listen to pg_notify",
"dependencies": {
"pg": "^8.3.0",
"node-red-contrib-re-postgres": "~0.2.2"
"pg": "~7.4.1",
"node-red-contrib-postgres": "~0.6.1"
},
"repository": {
"type": "git",
@ -26,4 +26,4 @@
"name": "Vincent Schoonenburg",
"email": "arkancrow@gmail.com"
}
}
}

View File

@ -25,7 +25,7 @@ module.exports = function(RED) {
this.channel = n.channel;
console.log(this.channel);
var node = this;
node.clientdb = null;
var clientdb = null;
this.status({fill:"red",shape:"ring",text:"disconnected"});
if(this.postgresConfig) {
@ -42,9 +42,9 @@ module.exports = function(RED) {
if (node.postgresConfig.db) { config.database = node.postgresConfig.db; }
config.ssl = node.postgresConfig.ssl;
}
node.clientdb = new pg.Client(config);
clientdb = new pg.Client(config);
node.clientdb.connect(function(err) {
clientdb.connect(function(err) {
try {
if(err) {
@ -53,21 +53,14 @@ module.exports = function(RED) {
} else {
console.log("Connected");
node.status({fill:"green",shape:"dot",text:"connected"});
node.clientdb.on('notification', function(msg) {
try {
var outmsg = {};
outmsg.payload = JSON.parse(msg.payload);
delete msg.payload;
outmsg.topic = msg.channel;
delete msg.channel;
outmsg.pg_data = msg;
node.send(outmsg);
} catch (error) {
node.error(error);
}
clientdb.on('notification', function(msg) {
console.log("Notification received");
msg.payload = JSON.parse(msg.payload);
node.log(JSON.stringify(msg));
node.send(msg);
});
var query = "LISTEN " + node.channel;
node.clientdb.query(query);
clientdb.query(query);
console.log("Listening to :" + node.channel);
}
} catch (error) {