Giter Site home page Giter Site logo

node-red-contrib-postgres-variable's Introduction

node-red-contrib-postgres-variable

A Node-RED node to query PostgreSQL.

Edited by Andrii Lototskyi

Install

Run the following command in the root directory of your Node-RED install

npm install node-red-contrib-postgres-variable

The node-red postgres node uses a template node to set the query and uses msg.queryParameters as params for the query. Each property in msg.queryParameters can be used as $propertyName in the query, see the 'setup params' and 'format query' node in the example. The msg it then passed to the postgres node. If you want the output of the query, check the 'Receive output' box in the postgres node. The result of the query is then set on the msg.payload property which can be sent to a http node. Data for connection can be obtained from the file settings.js

Set Credentials

add data to settings.js

pgConnects: {
    connect1: {
        user: "usernameToDB",
        password: "userPasswordToDB",
        host: "hostName",
        port: "port",
        database: "dataBaseName",
        ssl: false // true/false
     },
    connect2 {
        user: "usernameToDB",
        password: "userPasswordToDB",
        host: "hostName",
        port: "port",
        database: "dataBaseName",
        ssl: false // true/false
    },
    connect3 {
        user: "usernameToDB",
        password: "userPasswordToDB",
        host: "hostName",
        port: "port",
        database: "dataBaseName",
        ssl: false // true/false
    }
},

Example For Request

set data in function node

msg.payload = "SELECT NOW()";
msg.connectName = 'connect1';  // connect name from settings.js
return msg;

Example DB

CREATE TABLE public.table1
(
    field1 character varying,
    field2 integer
)
WITH (
    OIDS=FALSE
);
ALTER TABLE public.table1
  OWNER TO postgres;

INSERT INTO public.table1(
            field1, field2)
    VALUES ('row1',1);
INSERT INTO public.table1(
            field1, field2)
    VALUES ('row2',2);

Example node-red flow

Import the flow below in an empty sheet in nodered

[{"id":"35c76478.e1723c","type":"function","z":"25b7c5b4.6f1eba","name":"setup params","func":"msg.queryParameters = msg.queryParameters || {};\nmsg.queryParameters.param1 = 1;\nmsg.connectName = 'connect1';\nreturn msg;","outputs":1,"noerr":0,"x":273,"y":96,"wires":[["740c574e.518e28"]]}]

node-red-contrib-postgres-variable's People

Contributors

lotockii avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-red-contrib-postgres-variable's Issues

Conflict with flow constant

Hi,

I'm seeing a very strange issue while using "node-red-contrib-postgres-variable". For some reason when I use this node I can't set a flow constant in one branch and get the flow constant in a different branch. I can get it in the same branch. If i remove the "node-red-contrib-postgres-variable" node it works fine. Has anyone else seen this are am I doing something really stupid?

When using the node I also see more errors in the flow. Like timeout errors.

[{"id":"b5423d16.2f2fe","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"36483a44.8b46a6","type":"inject","z":"b5423d16.2f2fe","name":"inject1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":111,"y":190,"wires":[["b3370a35.5fec48"]]},{"id":"27f185b9.9f29ca","type":"function","z":"b5423d16.2f2fe","name":"StoreConfig","func":"//flow.set('config', msg.payload);\nflow.set('config', 'test');\nvar config = flow.get('config');\nmsg.payload = config;\nreturn msg;\n","outputs":1,"noerr":0,"x":749,"y":192,"wires":[["9fcfffd7.912ba","9cd8db3a.d6a538"]]},{"id":"9fcfffd7.912ba","type":"debug","z":"b5423d16.2f2fe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":927,"y":197,"wires":[]},{"id":"9cd8db3a.d6a538","type":"function","z":"b5423d16.2f2fe","name":"GetConfig","func":"var config = flow.get('config');\nmsg.payload = config;\nreturn msg;\n","outputs":1,"noerr":0,"x":560.5,"y":278,"wires":[["5c20ae15.7140b"]]},{"id":"5c20ae15.7140b","type":"debug","z":"b5423d16.2f2fe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":728.5,"y":283,"wires":[]},{"id":"e9555e53.7140c","type":"inject","z":"b5423d16.2f2fe","name":"inject2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":362,"y":279,"wires":[["9cd8db3a.d6a538"]]},{"id":"b3370a35.5fec48","type":"function","z":"b5423d16.2f2fe","name":"Query","func":"msg.payload = \"SELECT DISTINCT \\\"RoomName\\\", \\\"DeviceID\\\", \\\"Active\\\" \" +\n\t \"FROM public.configuration\";\nreturn msg;","outputs":1,"noerr":0,"x":326,"y":164,"wires":[["d5b6494d.9728c8"]]},{"id":"d5b6494d.9728c8","type":"postgres","z":"b5423d16.2f2fe","postgresdb":"c4ed9674.384ab8","name":"AvailableRooms","output":true,"outputs":1,"x":522,"y":169,"wires":[["27f185b9.9f29ca"]]},{"id":"c4ed9674.384ab8","type":"postgresdb","z":"","hostname":"localhost","port":"5432","db":"heating","ssl":false}]

Thanks

UnhandledPromiseRejectionWarning

Hi. Thanks for the great plugin. However, I am constantly getting this kind of log in Node-RED logs. Any idea how could I make this go away?

(node:7785) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 23) (node:7785) UnhandledPromiseRejectionWarning: Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:393:12) at Connection.end (/usr/lib/node/node-red/node_modules/node-red-contrib-postgres-variable/node_modules/pg/lib/connection.js:318:22) at global.Promise (/usr/lib/node/node-red/node_modules/node-red-contrib-postgres-variable/node_modules/pg/lib/client.js:410:23) at new Promise (<anonymous>) at Client.end (/usr/lib/node/node-red/node_modules/node-red-contrib-postgres-variable/node_modules/pg/lib/client.js:409:12) at Pool._remove (/usr/lib/node/node-red/node_modules/node-red-contrib-postgres-variable/node_modules/pg-pool/index.js:142:12) at Timeout.setTimeout (/usr/lib/node/node-red/node_modules/node-red-contrib-postgres-variable/node_modules/pg-pool/index.js:298:14) at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5)

Version: 0.0.18
Node version: 10.15.3

Unable to find code for version 0.0.14

I have find the node version 0.0.14 in npm registry. But the code is not updated here. It is still in the older version, 0.0.11. Are you guys going to maintain an updated the code here for others to see? or just going to update it in npm registry?

Please use node-red-contrib- naming for your module

Hi there - thanks for creating a node and sharing it with the community.

One request - as per our packaging guidelines, we ask that 3rd party nodes use the node-red-contrib- prefix to their name. This ensures they don't get mistaken for nodes maintained by the project itself.

You're under no obligation to change the name, but I hope you'll consider it.

Many thanks, Nick

Error: Connection terminated due to connection timeout

After updating Node JS and Node-RED to the latest version:

Node.js(v14.17.6)
Node-RED(v2.0.6)

After running the program, I get a connection timeout error:

22 Sep 12:19:35 - [error] [postgres:bb05df0a8b7ba064] {"type":"postgres error","request":"SELECT * FROM public.\"tblStudent\";","error":{}}
{
  type: 'postgres error',
  request: 'SELECT * FROM public."tblStudent";',
  error: Error: Connection terminated due to connection timeout
      at Connection. (C:\Users\mhoang\.node-red\node_modules\pg\lib\client.js:179:21)
      at Object.onceWrapper (events.js:519:28)
      at Connection.emit (events.js:400:28)
      at Socket. (C:\Users\mhoang\.node-red\node_modules\pg\lib\connection.js:76:10)
      at Socket.emit (events.js:400:28)
      at emitCloseNT (net.js:1661:8)
      at processTicksAndRejections (internal/process/task_queues.js:81:21)
}

postgreErrConnTimeout

Could it be that the postgres (node-red-contrib-postgres-variable) node is not compatible with the latest version?

Node postgre worked fine before update with:

Node.js(v12.7.0)
Node-RED(v0.20.7)

I'm using:
Windows 10 Pro
node-red-contrib-postgres-variable(v0.1.4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.