node-red mysql的增删改查

最近一段时间在学node-red,碰到过很多问题。收获也是很多,下面这个是一个node-red的小案例,主要就是用node-red实现mysql的增删改查。

效果图:
node-red mysql的增删改查_第1张图片

查询
node-red mysql的增删改查_第2张图片
源码:
[{"id":"24ba3f58.22ccf","type":"inject","z":"ede2a284.edabc","name":"Go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":514,"y":119,"wires":[["7523b3de.bc5f1c"]]},{"id":"7523b3de.bc5f1c","type":"function","z":"ede2a284.edabc","name":"INSERT Data","func":"msg.topic = \"INSERT INTO ?? (??,??) VALUES (?,?)\";\nmsg.payload = [\"mysqls.dept\",\"id\",\"name\",\"3\",\"333\"];\nreturn msg;","outputs":1,"noerr":0,"x":709,"y":137,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"92ba86cf.fd8e68","type":"debug","z":"ede2a284.edabc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":995,"y":98.00003051757812,"wires":[]},{"id":"f0b619ca.27a748","type":"inject","z":"ede2a284.edabc","name":"Go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":515,"y":179,"wires":[["f17f7ce4.7ab42"]]},{"id":"f17f7ce4.7ab42","type":"function","z":"ede2a284.edabc","name":"Update Data","func":"msg.topic = \"Update Department Set Department_name = ? where Department_id=?\";\nmsg.payload=['Logistics Managers','3']\nreturn msg;","outputs":1,"noerr":0,"x":697,"y":187,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"1d28db6f.7bcc85","type":"inject","z":"ede2a284.edabc","name":"Go","topic":"","payload":"warehouse","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":214,"y":309,"wires":[["7ebd2055.9940f"]]},{"id":"7ebd2055.9940f","type":"function","z":"ede2a284.edabc","name":"SELECT Data","func":"msg.topic = \"SELECT * FROM mysqls.dept \";\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":351,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"a52275f5.22eb58","type":"inject","z":"ede2a284.edabc","name":"INSERT Bind - via JSON","topic":"INSERT INTO test (id,text) VALUES (?, ?)","payload":"[4, \"This is a funny world's end\"]","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":525,"y":233,"wires":[["109caf56.457401"]]},{"id":"109caf56.457401","type":"json","z":"ede2a284.edabc","name":"","property":"payload","action":"","pretty":false,"x":742,"y":237,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"55a117e9.dcd708","type":"inject","z":"ede2a284.edabc","name":"Go \"Warehouse\"","topic":"","payload":"%部%","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":503,"y":484,"wires":[["5cb06792.ba9c08"]]},{"id":"5cb06792.ba9c08","type":"function","z":"ede2a284.edabc","name":"SELECT Data","func":"msg.topic = \"SELECT * FROM mysqls.dept WHERE Name LIKE ?\";\nmsg.payload = [msg.payload];\nreturn msg;","outputs":1,"noerr":0,"x":719,"y":438,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"d8b29c2a.7e634","type":"inject","z":"ede2a284.edabc","name":"Go \"MAnagers\"","topic":"","payload":"%技术%","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":545,"y":555,"wires":[["5cb06792.ba9c08"]]},{"id":"a4fb4c4c.6ecfb","type":"mysql","z":"ede2a284.edabc","mydb":"558e03da.b3e96c","name":"","x":983,"y":193,"wires":[["92ba86cf.fd8e68","b6482a84.6b7868"]]},{"id":"a36af90a.7ed028","type":"function","z":"ede2a284.edabc","name":"Delete Bind","func":"msg.topic = \"Delete From mysqls.dept where name = ?\";\nmsg.payload = [ \"333\"];\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":291,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"246754ef.204cfc","type":"inject","z":"ede2a284.edabc","name":"Go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":544,"y":283,"wires":[["a36af90a.7ed028"]]},{"id":"4a5a722f.e02e0c","type":"function","z":"ede2a284.edabc","name":"INSERT Data","func":"msg.topic = \"INSERT INTO department (department_name) VALUES (?)\";\nmsg.payload = [ \"test\"];\nreturn msg;\n\nmsg.topic = \"INSERT INTO ?? (??) VALUES (?)\";\nmsg.payload = [\"Department\",\"Department_name\",\"test\"];\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":71,"wires":[["a4fb4c4c.6ecfb"]]},{"id":"9688b952.62c1a8","type":"inject","z":"ede2a284.edabc","name":"Go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":517,"y":59,"wires":[["4a5a722f.e02e0c"]]},{"id":"fdf0217a.7932","type":"http in","z":"ede2a284.edabc","name":"通过路径发送get请求(/hello-data)","url":"/hello-data","method":"get","upload":false,"swaggerDoc":"","x":200,"y":257.14996337890625,"wires":[["7ebd2055.9940f"]]},{"id":"2bee93b2.5fc2dc","type":"http response","z":"ede2a284.edabc","name":"http_tweets_response","statusCode":"","headers":{},"x":1041,"y":538,"wires":[]},{"id":"27db10fa.b4805","type":"template","z":"ede2a284.edabc","name":"html","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n  \n    My Tweets from MySQL\n    \n    \n  \n  {{{payload}}}\n\n\n","output":"str","x":999,"y":461,"wires":[["2bee93b2.5fc2dc"]]},{"id":"b6482a84.6b7868","type":"json","z":"ede2a284.edabc","name":"","property":"payload","action":"","pretty":false,"x":1009,"y":284,"wires":[["c64fca45.521958"]]},{"id":"c64fca45.521958","type":"function","z":"ede2a284.edabc","name":"tweet_func","func":"var json = JSON.parse(msg.payload);\nvar html = '
';\nhtml =json.reduce( function(prevVal, currentVal, currIndex, arr) {\n return  prevVal+\"\";\n}, html);\nhtml += '
IDcodenamelevelparentLevel
\"+currentVal.id + \"\" + currentVal.code+\"\" + currentVal.name+\"\" + currentVal.level+\"\" + currentVal.parentLevel+\"
';\n//json.setEncoding('utf8');\nmsg.payload=html;\nreturn msg;\n","outputs":1,"noerr":0,"x":1022,"y":367,"wires":[["27db10fa.b4805"]]},{"id":"1960133e.f85b7d","type":"inject","z":"ede2a284.edabc","name":"时刻刷新","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":218,"y":362.14996337890625,"wires":[["7ebd2055.9940f"]]},{"id":"6dbb8901.4b6108","type":"function","z":"ede2a284.edabc","name":"INSERT Data","func":"msg.topic = \"INSERT INTO ?? (??,??) VALUES (?,?)\";\nmsg.payload = [\"mysqls.dept\",\"id\",\"name\",msg.payload.name,\"333\"];\nreturn msg;","outputs":1,"noerr":0,"x":218,"y":421,"wires":[["f0b1c2b8.87235"]]},{"id":"4ecc3158.095bb","type":"http in","z":"ede2a284.edabc","name":"","url":"/hello-query","method":"get","upload":false,"swaggerDoc":"","x":203,"y":507,"wires":[["6dbb8901.4b6108"]]},{"id":"f0b1c2b8.87235","type":"mysql","z":"ede2a284.edabc","mydb":"558e03da.b3e96c","name":"","x":495,"y":401,"wires":[["7ebd2055.9940f"]]},{"id":"558e03da.b3e96c","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"mysqls","tz":""}]

你可能感兴趣的:(node-red mysql的增删改查)