当前位置:   article > 正文

Node-RED中连接Mysql数据库并实现增删改查的操作_nodered查找最新数据

nodered查找最新数据

场景

Node-RED中建立静态网页和动态网页内容:

Node-RED中建立静态网页和动态网页内容_霸道流氓气质的博客-CSDN博客

在上面的基础上,怎样实现连接Mysql数据库并将数据库中的数据显示在网页上,以及执行插入、更新、删除操作。

注:

博客:
霸道流氓气质的博客_CSDN博客-C#,架构之路,SpringBoot领域博主
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、安装NodeRED节点

节点管理搜索node-red-node-mysql,安装

安装成功之后就会有Mysql节点了

2、数据库设计一个测试的用户表

流程设计如下

编辑function节点,使其执行查询语句

  1. msg.topic = "SELECT * FROM user";
  2. return msg;

3、编辑Mysql节点

编辑连接输入数据库连接信息

4、编辑template节点修改html显示模板

  1. <html>
  2. <head>
  3. <title>用户</title>
  4. </head>
  5. <body>
  6. <table border="1">
  7. {{#payload}}
  8. <tr><td>{{name}}</td><td>{{pass}}</td></tr>
  9. {{/payload}}
  10. </table>
  11. </body>
  12. </html>

5、部署运行访问

http://127.0.0.1:1880/allUser

6、查询流程json数据

  1. [
  2. {
  3. "id": "f4a4d8eab7935bc8",
  4. "type": "tab",
  5. "label": "流程 3",
  6. "disabled": false,
  7. "info": "",
  8. "env": []
  9. },
  10. {
  11. "id": "c428312d1f6165d1",
  12. "type": "mqtt-broker",
  13. "name": "mqtt",
  14. "broker": "127.0.0.1",
  15. "port": "1883",
  16. "clientid": "",
  17. "autoConnect": true,
  18. "usetls": false,
  19. "protocolVersion": "4",
  20. "keepalive": "60",
  21. "cleansession": true,
  22. "birthTopic": "",
  23. "birthQos": "0",
  24. "birthPayload": "",
  25. "birthMsg": {},
  26. "closeTopic": "",
  27. "closeQos": "0",
  28. "closePayload": "",
  29. "closeMsg": {},
  30. "willTopic": "",
  31. "willQos": "0",
  32. "willPayload": "",
  33. "willMsg": {},
  34. "sessionExpiry": ""
  35. },
  36. {
  37. "id": "51eee50b4ec9422f",
  38. "type": "ui_group",
  39. "name": "dashboardDemo",
  40. "tab": "29ae4c620f43ee0d",
  41. "order": 1,
  42. "disp": true,
  43. "width": "6",
  44. "collapse": false,
  45. "className": ""
  46. },
  47. {
  48. "id": "29ae4c620f43ee0d",
  49. "type": "ui_tab",
  50. "name": "Home",
  51. "icon": "dashboard",
  52. "disabled": false,
  53. "hidden": false
  54. },
  55. {
  56. "id": "a506c767a5c1edbd",
  57. "type": "ui_base",
  58. "theme": {
  59. "name": "theme-light",
  60. "lightTheme": {
  61. "default": "#0094CE",
  62. "baseColor": "#0094CE",
  63. "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
  64. "edited": true,
  65. "reset": false
  66. },
  67. "darkTheme": {
  68. "default": "#097479",
  69. "baseColor": "#097479",
  70. "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
  71. "edited": false
  72. },
  73. "customTheme": {
  74. "name": "Untitled Theme 1",
  75. "default": "#4B7930",
  76. "baseColor": "#4B7930",
  77. "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
  78. },
  79. "themeState": {
  80. "base-color": {
  81. "default": "#0094CE",
  82. "value": "#0094CE",
  83. "edited": false
  84. },
  85. "page-titlebar-backgroundColor": {
  86. "value": "#0094CE",
  87. "edited": false
  88. },
  89. "page-backgroundColor": {
  90. "value": "#fafafa",
  91. "edited": false
  92. },
  93. "page-sidebar-backgroundColor": {
  94. "value": "#ffffff",
  95. "edited": false
  96. },
  97. "group-textColor": {
  98. "value": "#1bbfff",
  99. "edited": false
  100. },
  101. "group-borderColor": {
  102. "value": "#ffffff",
  103. "edited": false
  104. },
  105. "group-backgroundColor": {
  106. "value": "#ffffff",
  107. "edited": false
  108. },
  109. "widget-textColor": {
  110. "value": "#111111",
  111. "edited": false
  112. },
  113. "widget-backgroundColor": {
  114. "value": "#0094ce",
  115. "edited": false
  116. },
  117. "widget-borderColor": {
  118. "value": "#ffffff",
  119. "edited": false
  120. },
  121. "base-font": {
  122. "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
  123. }
  124. },
  125. "angularTheme": {
  126. "primary": "indigo",
  127. "accents": "blue",
  128. "warn": "red",
  129. "background": "grey",
  130. "palette": "light"
  131. }
  132. },
  133. "site": {
  134. "name": "Node-RED Dashboard",
  135. "hideToolbar": "false",
  136. "allowSwipe": "false",
  137. "lockMenu": "false",
  138. "allowTempTheme": "true",
  139. "dateFormat": "DD/MM/YYYY",
  140. "sizes": {
  141. "sx": 48,
  142. "sy": 48,
  143. "gx": 6,
  144. "gy": 6,
  145. "cx": 6,
  146. "cy": 6,
  147. "px": 0,
  148. "py": 0
  149. }
  150. }
  151. },
  152. {
  153. "id": "248cbbb0.18e794",
  154. "type": "ui_group",
  155. "name": "MyGroup",
  156. "tab": "3f79c420.cfc1bc",
  157. "order": 1,
  158. "disp": true,
  159. "width": "6",
  160. "collapse": false
  161. },
  162. {
  163. "id": "3f79c420.cfc1bc",
  164. "type": "ui_tab",
  165. "name": "Home",
  166. "icon": "dashboard",
  167. "disabled": false,
  168. "hidden": false
  169. },
  170. {
  171. "id": "a0954be5.a7f7e8",
  172. "type": "ui_group",
  173. "name": "MyInput",
  174. "tab": "3f79c420.cfc1bc",
  175. "order": 2,
  176. "disp": true,
  177. "width": "6",
  178. "collapse": false
  179. },
  180. {
  181. "id": "508bd6f8398ab80f",
  182. "type": "ui_group",
  183. "name": "OpenWeatherMap",
  184. "tab": "3f79c420.cfc1bc",
  185. "order": 3,
  186. "disp": true,
  187. "width": "6",
  188. "collapse": false
  189. },
  190. {
  191. "id": "8824dea1.83e31",
  192. "type": "websocket-client",
  193. "path": "ws://localhost:9898/",
  194. "tls": "",
  195. "wholemsg": "false"
  196. },
  197. {
  198. "id": "51c3503.61936b",
  199. "type": "MySQLdatabase",
  200. "name": "",
  201. "host": "127.0.0.1",
  202. "port": "3306",
  203. "db": "test",
  204. "tz": "",
  205. "charset": "UTF8"
  206. },
  207. {
  208. "id": "571a8ee8.5883d",
  209. "type": "http in",
  210. "z": "f4a4d8eab7935bc8",
  211. "name": "",
  212. "url": "/allUser",
  213. "method": "get",
  214. "upload": false,
  215. "swaggerDoc": "",
  216. "x": 210,
  217. "y": 160,
  218. "wires": [
  219. [
  220. "71ec3368.c3cf5c"
  221. ]
  222. ]
  223. },
  224. {
  225. "id": "7eb81f73.1710c",
  226. "type": "template",
  227. "z": "f4a4d8eab7935bc8",
  228. "name": "HTML网页",
  229. "field": "payload",
  230. "fieldType": "msg",
  231. "format": "handlebars",
  232. "syntax": "mustache",
  233. "template": "<html>\n <head>\n <title>用户</title>\n </head>\n <body>\n <table border=\"1\">\n {{#payload}}\n <tr><td>{{name}}</td><td>{{pass}}</td></tr>\n {{/payload}}\n </table>\n </body>\n</html>",
  234. "x": 570,
  235. "y": 160,
  236. "wires": [
  237. [
  238. "766f42f9.87fbcc"
  239. ]
  240. ]
  241. },
  242. {
  243. "id": "71ec3368.c3cf5c",
  244. "type": "function",
  245. "z": "f4a4d8eab7935bc8",
  246. "name": "SQL Query",
  247. "func": "msg.topic = \"SELECT * FROM user\";\nreturn msg;",
  248. "outputs": 1,
  249. "noerr": 0,
  250. "initialize": "",
  251. "finalize": "",
  252. "libs": [],
  253. "x": 290,
  254. "y": 240,
  255. "wires": [
  256. [
  257. "1c7d1dcf.bb2ad2"
  258. ]
  259. ]
  260. },
  261. {
  262. "id": "766f42f9.87fbcc",
  263. "type": "http response",
  264. "z": "f4a4d8eab7935bc8",
  265. "name": "",
  266. "statusCode": "",
  267. "headers": {},
  268. "x": 610,
  269. "y": 240,
  270. "wires": []
  271. },
  272. {
  273. "id": "1c7d1dcf.bb2ad2",
  274. "type": "mysql",
  275. "z": "f4a4d8eab7935bc8",
  276. "mydb": "51c3503.61936b",
  277. "name": "",
  278. "x": 410,
  279. "y": 160,
  280. "wires": [
  281. [
  282. "7eb81f73.1710c"
  283. ]
  284. ]
  285. }
  286. ]

7、实现插入操作

新增插入数据的流程设计

编辑function节点,编辑插入语句

执行查看效果

插入流程json数据

  1. [
  2. {
  3. "id": "1d9518ddb606e944",
  4. "type": "inject",
  5. "z": "f4a4d8eab7935bc8",
  6. "name": "",
  7. "props": [
  8. {
  9. "p": "payload"
  10. },
  11. {
  12. "p": "topic",
  13. "vt": "str"
  14. }
  15. ],
  16. "repeat": "",
  17. "crontab": "",
  18. "once": false,
  19. "onceDelay": 0.1,
  20. "topic": "",
  21. "payloadType": "date",
  22. "x": 210,
  23. "y": 380,
  24. "wires": [
  25. [
  26. "e28fd0d0403014e0"
  27. ]
  28. ]
  29. },
  30. {
  31. "id": "e28fd0d0403014e0",
  32. "type": "function",
  33. "z": "f4a4d8eab7935bc8",
  34. "name": "INSERT",
  35. "func": "\nvar user = 'insertUser';\nvar pass = '123456';\n\nmsg.topic = \"INSERT INTO user \" +\n \"(name,pass)\" +\n \"VALUES ('\" + user +\n \"','\"+ pass + \"' )\";\nreturn msg;",
  36. "outputs": 1,
  37. "noerr": 0,
  38. "initialize": "",
  39. "finalize": "",
  40. "libs": [],
  41. "x": 340,
  42. "y": 380,
  43. "wires": [
  44. [
  45. "fdde79cf9a1b1722"
  46. ]
  47. ]
  48. },
  49. {
  50. "id": "fdde79cf9a1b1722",
  51. "type": "mysql",
  52. "z": "f4a4d8eab7935bc8",
  53. "mydb": "51c3503.61936b",
  54. "name": "",
  55. "x": 480,
  56. "y": 380,
  57. "wires": [
  58. [
  59. "5ea56f3eec020d0f"
  60. ]
  61. ]
  62. },
  63. {
  64. "id": "5ea56f3eec020d0f",
  65. "type": "debug",
  66. "z": "f4a4d8eab7935bc8",
  67. "name": "",
  68. "active": true,
  69. "tosidebar": true,
  70. "console": false,
  71. "tostatus": false,
  72. "complete": "payload",
  73. "targetType": "msg",
  74. "statusVal": "",
  75. "statusType": "auto",
  76. "x": 630,
  77. "y": 380,
  78. "wires": []
  79. },
  80. {
  81. "id": "51c3503.61936b",
  82. "type": "MySQLdatabase",
  83. "name": "",
  84. "host": "127.0.0.1",
  85. "port": "3306",
  86. "db": "test",
  87. "tz": "",
  88. "charset": "UTF8",
  89. "credentials": {}
  90. }
  91. ]

8、新增更新语句执行流程设计如下

模板值可以在字符找那个嵌入运算式或变量。

但是注意的是字符串是使用反引号,在Tab上方的按钮括起,而不是使用单引号括起。

编辑function节点

  1. var id = 3;
  2. var name = 'updateName';
  3. var pass = '5555';
  4. msg.topic = `UPDATE user SET name='${name}',` +
  5. `pass='${pass}' WHERE id=${id}`;
  6. return msg;

部署运行看效果

更新流程json数据

  1. [
  2. {
  3. "id": "5426aed100d65d31",
  4. "type": "inject",
  5. "z": "f4a4d8eab7935bc8",
  6. "name": "",
  7. "repeat": "",
  8. "crontab": "",
  9. "once": false,
  10. "onceDelay": 0.1,
  11. "topic": "",
  12. "payload": "",
  13. "payloadType": "date",
  14. "x": 210,
  15. "y": 520,
  16. "wires": [
  17. [
  18. "a911307ea6b68a16"
  19. ]
  20. ]
  21. },
  22. {
  23. "id": "a911307ea6b68a16",
  24. "type": "function",
  25. "z": "f4a4d8eab7935bc8",
  26. "name": "UPDATE",
  27. "func": "var id = 3;\nvar name = 'updateName';\nvar pass = '5555';\nmsg.topic = `UPDATE user SET name='${name}',` +\n `pass='${pass}' WHERE id=${id}`;\nreturn msg;",
  28. "outputs": 1,
  29. "noerr": 0,
  30. "initialize": "",
  31. "finalize": "",
  32. "libs": [],
  33. "x": 340,
  34. "y": 520,
  35. "wires": [
  36. [
  37. "eb4b3bd2a53dbb37",
  38. "d991b7f159d90812"
  39. ]
  40. ]
  41. },
  42. {
  43. "id": "eb4b3bd2a53dbb37",
  44. "type": "mysql",
  45. "z": "f4a4d8eab7935bc8",
  46. "mydb": "51c3503.61936b",
  47. "name": "",
  48. "x": 480,
  49. "y": 520,
  50. "wires": [
  51. [
  52. "c83545834bc01135"
  53. ]
  54. ]
  55. },
  56. {
  57. "id": "c83545834bc01135",
  58. "type": "debug",
  59. "z": "f4a4d8eab7935bc8",
  60. "name": "",
  61. "active": true,
  62. "tosidebar": true,
  63. "console": false,
  64. "tostatus": false,
  65. "complete": "payload",
  66. "targetType": "msg",
  67. "statusVal": "",
  68. "statusType": "auto",
  69. "x": 630,
  70. "y": 520,
  71. "wires": []
  72. },
  73. {
  74. "id": "d991b7f159d90812",
  75. "type": "debug",
  76. "z": "f4a4d8eab7935bc8",
  77. "name": "",
  78. "active": true,
  79. "tosidebar": true,
  80. "console": false,
  81. "tostatus": false,
  82. "complete": "topic",
  83. "targetType": "msg",
  84. "statusVal": "",
  85. "statusType": "auto",
  86. "x": 480,
  87. "y": 600,
  88. "wires": []
  89. },
  90. {
  91. "id": "51c3503.61936b",
  92. "type": "MySQLdatabase",
  93. "name": "",
  94. "host": "127.0.0.1",
  95. "port": "3306",
  96. "db": "test",
  97. "tz": "",
  98. "charset": "UTF8"
  99. }
  100. ]

9、设计删除流程布局

编辑template节点

DELETE FROM user WHERE id='{{payload}}'

部署运行查看效果

 

删除流程json数据

  1. [
  2. {
  3. "id": "883fb789f22f352f",
  4. "type": "inject",
  5. "z": "f4a4d8eab7935bc8",
  6. "name": "",
  7. "props": [
  8. {
  9. "p": "payload"
  10. },
  11. {
  12. "p": "topic",
  13. "vt": "str"
  14. }
  15. ],
  16. "repeat": "",
  17. "crontab": "",
  18. "once": false,
  19. "onceDelay": 0.1,
  20. "topic": "",
  21. "payload": "1",
  22. "payloadType": "str",
  23. "x": 210,
  24. "y": 720,
  25. "wires": [
  26. [
  27. "15479540478f4720"
  28. ]
  29. ]
  30. },
  31. {
  32. "id": "fd30c40a7a9d0baf",
  33. "type": "mysql",
  34. "z": "f4a4d8eab7935bc8",
  35. "mydb": "51c3503.61936b",
  36. "name": "",
  37. "x": 480,
  38. "y": 720,
  39. "wires": [
  40. [
  41. "6eb37dd7c809dd01"
  42. ]
  43. ]
  44. },
  45. {
  46. "id": "6eb37dd7c809dd01",
  47. "type": "debug",
  48. "z": "f4a4d8eab7935bc8",
  49. "name": "",
  50. "active": true,
  51. "tosidebar": true,
  52. "console": false,
  53. "tostatus": false,
  54. "complete": "payload",
  55. "targetType": "msg",
  56. "statusVal": "",
  57. "statusType": "auto",
  58. "x": 630,
  59. "y": 720,
  60. "wires": []
  61. },
  62. {
  63. "id": "15479540478f4720",
  64. "type": "template",
  65. "z": "f4a4d8eab7935bc8",
  66. "name": "DELETE",
  67. "field": "topic",
  68. "fieldType": "msg",
  69. "format": "handlebars",
  70. "syntax": "mustache",
  71. "template": "DELETE FROM user WHERE id='{{payload}}'",
  72. "output": "str",
  73. "x": 340,
  74. "y": 720,
  75. "wires": [
  76. [
  77. "fd30c40a7a9d0baf"
  78. ]
  79. ]
  80. },
  81. {
  82. "id": "51c3503.61936b",
  83. "type": "MySQLdatabase",
  84. "name": "",
  85. "host": "127.0.0.1",
  86. "port": "3306",
  87. "db": "test",
  88. "tz": "",
  89. "charset": "UTF8"
  90. }
  91. ]

10、增删改查全流程json数据

  1. [
  2. {
  3. "id": "f4a4d8eab7935bc8",
  4. "type": "tab",
  5. "label": "流程 3",
  6. "disabled": false,
  7. "info": "",
  8. "env": []
  9. },
  10. {
  11. "id": "c428312d1f6165d1",
  12. "type": "mqtt-broker",
  13. "name": "mqtt",
  14. "broker": "127.0.0.1",
  15. "port": "1883",
  16. "clientid": "",
  17. "autoConnect": true,
  18. "usetls": false,
  19. "protocolVersion": "4",
  20. "keepalive": "60",
  21. "cleansession": true,
  22. "birthTopic": "",
  23. "birthQos": "0",
  24. "birthPayload": "",
  25. "birthMsg": {},
  26. "closeTopic": "",
  27. "closeQos": "0",
  28. "closePayload": "",
  29. "closeMsg": {},
  30. "willTopic": "",
  31. "willQos": "0",
  32. "willPayload": "",
  33. "willMsg": {},
  34. "sessionExpiry": ""
  35. },
  36. {
  37. "id": "51eee50b4ec9422f",
  38. "type": "ui_group",
  39. "name": "dashboardDemo",
  40. "tab": "29ae4c620f43ee0d",
  41. "order": 1,
  42. "disp": true,
  43. "width": "6",
  44. "collapse": false,
  45. "className": ""
  46. },
  47. {
  48. "id": "29ae4c620f43ee0d",
  49. "type": "ui_tab",
  50. "name": "Home",
  51. "icon": "dashboard",
  52. "disabled": false,
  53. "hidden": false
  54. },
  55. {
  56. "id": "a506c767a5c1edbd",
  57. "type": "ui_base",
  58. "theme": {
  59. "name": "theme-light",
  60. "lightTheme": {
  61. "default": "#0094CE",
  62. "baseColor": "#0094CE",
  63. "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
  64. "edited": true,
  65. "reset": false
  66. },
  67. "darkTheme": {
  68. "default": "#097479",
  69. "baseColor": "#097479",
  70. "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
  71. "edited": false
  72. },
  73. "customTheme": {
  74. "name": "Untitled Theme 1",
  75. "default": "#4B7930",
  76. "baseColor": "#4B7930",
  77. "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
  78. },
  79. "themeState": {
  80. "base-color": {
  81. "default": "#0094CE",
  82. "value": "#0094CE",
  83. "edited": false
  84. },
  85. "page-titlebar-backgroundColor": {
  86. "value": "#0094CE",
  87. "edited": false
  88. },
  89. "page-backgroundColor": {
  90. "value": "#fafafa",
  91. "edited": false
  92. },
  93. "page-sidebar-backgroundColor": {
  94. "value": "#ffffff",
  95. "edited": false
  96. },
  97. "group-textColor": {
  98. "value": "#1bbfff",
  99. "edited": false
  100. },
  101. "group-borderColor": {
  102. "value": "#ffffff",
  103. "edited": false
  104. },
  105. "group-backgroundColor": {
  106. "value": "#ffffff",
  107. "edited": false
  108. },
  109. "widget-textColor": {
  110. "value": "#111111",
  111. "edited": false
  112. },
  113. "widget-backgroundColor": {
  114. "value": "#0094ce",
  115. "edited": false
  116. },
  117. "widget-borderColor": {
  118. "value": "#ffffff",
  119. "edited": false
  120. },
  121. "base-font": {
  122. "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
  123. }
  124. },
  125. "angularTheme": {
  126. "primary": "indigo",
  127. "accents": "blue",
  128. "warn": "red",
  129. "background": "grey",
  130. "palette": "light"
  131. }
  132. },
  133. "site": {
  134. "name": "Node-RED Dashboard",
  135. "hideToolbar": "false",
  136. "allowSwipe": "false",
  137. "lockMenu": "false",
  138. "allowTempTheme": "true",
  139. "dateFormat": "DD/MM/YYYY",
  140. "sizes": {
  141. "sx": 48,
  142. "sy": 48,
  143. "gx": 6,
  144. "gy": 6,
  145. "cx": 6,
  146. "cy": 6,
  147. "px": 0,
  148. "py": 0
  149. }
  150. }
  151. },
  152. {
  153. "id": "248cbbb0.18e794",
  154. "type": "ui_group",
  155. "name": "MyGroup",
  156. "tab": "3f79c420.cfc1bc",
  157. "order": 1,
  158. "disp": true,
  159. "width": "6",
  160. "collapse": false
  161. },
  162. {
  163. "id": "3f79c420.cfc1bc",
  164. "type": "ui_tab",
  165. "name": "Home",
  166. "icon": "dashboard",
  167. "disabled": false,
  168. "hidden": false
  169. },
  170. {
  171. "id": "a0954be5.a7f7e8",
  172. "type": "ui_group",
  173. "name": "MyInput",
  174. "tab": "3f79c420.cfc1bc",
  175. "order": 2,
  176. "disp": true,
  177. "width": "6",
  178. "collapse": false
  179. },
  180. {
  181. "id": "508bd6f8398ab80f",
  182. "type": "ui_group",
  183. "name": "OpenWeatherMap",
  184. "tab": "3f79c420.cfc1bc",
  185. "order": 3,
  186. "disp": true,
  187. "width": "6",
  188. "collapse": false
  189. },
  190. {
  191. "id": "8824dea1.83e31",
  192. "type": "websocket-client",
  193. "path": "ws://localhost:9898/",
  194. "tls": "",
  195. "wholemsg": "false"
  196. },
  197. {
  198. "id": "51c3503.61936b",
  199. "type": "MySQLdatabase",
  200. "name": "",
  201. "host": "127.0.0.1",
  202. "port": "3306",
  203. "db": "test",
  204. "tz": "",
  205. "charset": "UTF8"
  206. },
  207. {
  208. "id": "571a8ee8.5883d",
  209. "type": "http in",
  210. "z": "f4a4d8eab7935bc8",
  211. "name": "",
  212. "url": "/allUser",
  213. "method": "get",
  214. "upload": false,
  215. "swaggerDoc": "",
  216. "x": 210,
  217. "y": 160,
  218. "wires": [
  219. [
  220. "71ec3368.c3cf5c"
  221. ]
  222. ]
  223. },
  224. {
  225. "id": "7eb81f73.1710c",
  226. "type": "template",
  227. "z": "f4a4d8eab7935bc8",
  228. "name": "HTML网页",
  229. "field": "payload",
  230. "fieldType": "msg",
  231. "format": "handlebars",
  232. "syntax": "mustache",
  233. "template": "<html>\n <head>\n <title>用户</title>\n </head>\n <body>\n <table border=\"1\">\n {{#payload}}\n <tr><td>{{name}}</td><td>{{pass}}</td></tr>\n {{/payload}}\n </table>\n </body>\n</html>",
  234. "x": 570,
  235. "y": 160,
  236. "wires": [
  237. [
  238. "766f42f9.87fbcc"
  239. ]
  240. ]
  241. },
  242. {
  243. "id": "71ec3368.c3cf5c",
  244. "type": "function",
  245. "z": "f4a4d8eab7935bc8",
  246. "name": "SQL Query",
  247. "func": "msg.topic = \"SELECT * FROM user\";\nreturn msg;",
  248. "outputs": 1,
  249. "noerr": 0,
  250. "initialize": "",
  251. "finalize": "",
  252. "libs": [],
  253. "x": 290,
  254. "y": 240,
  255. "wires": [
  256. [
  257. "1c7d1dcf.bb2ad2"
  258. ]
  259. ]
  260. },
  261. {
  262. "id": "766f42f9.87fbcc",
  263. "type": "http response",
  264. "z": "f4a4d8eab7935bc8",
  265. "name": "",
  266. "statusCode": "",
  267. "headers": {},
  268. "x": 610,
  269. "y": 240,
  270. "wires": []
  271. },
  272. {
  273. "id": "1c7d1dcf.bb2ad2",
  274. "type": "mysql",
  275. "z": "f4a4d8eab7935bc8",
  276. "mydb": "51c3503.61936b",
  277. "name": "",
  278. "x": 410,
  279. "y": 160,
  280. "wires": [
  281. [
  282. "7eb81f73.1710c"
  283. ]
  284. ]
  285. },
  286. {
  287. "id": "1d9518ddb606e944",
  288. "type": "inject",
  289. "z": "f4a4d8eab7935bc8",
  290. "name": "",
  291. "props": [
  292. {
  293. "p": "payload"
  294. },
  295. {
  296. "p": "topic",
  297. "vt": "str"
  298. }
  299. ],
  300. "repeat": "",
  301. "crontab": "",
  302. "once": false,
  303. "onceDelay": 0.1,
  304. "topic": "",
  305. "payloadType": "date",
  306. "x": 210,
  307. "y": 380,
  308. "wires": [
  309. [
  310. "e28fd0d0403014e0"
  311. ]
  312. ]
  313. },
  314. {
  315. "id": "e28fd0d0403014e0",
  316. "type": "function",
  317. "z": "f4a4d8eab7935bc8",
  318. "name": "INSERT",
  319. "func": "\nvar user = 'insertUser';\nvar pass = '123456';\n\nmsg.topic = \"INSERT INTO user \" +\n \"(name,pass)\" +\n \"VALUES ('\" + user +\n \"','\"+ pass + \"' )\";\nreturn msg;",
  320. "outputs": 1,
  321. "noerr": 0,
  322. "initialize": "",
  323. "finalize": "",
  324. "libs": [],
  325. "x": 340,
  326. "y": 380,
  327. "wires": [
  328. [
  329. "fdde79cf9a1b1722"
  330. ]
  331. ]
  332. },
  333. {
  334. "id": "fdde79cf9a1b1722",
  335. "type": "mysql",
  336. "z": "f4a4d8eab7935bc8",
  337. "mydb": "51c3503.61936b",
  338. "name": "",
  339. "x": 480,
  340. "y": 380,
  341. "wires": [
  342. [
  343. "5ea56f3eec020d0f"
  344. ]
  345. ]
  346. },
  347. {
  348. "id": "5ea56f3eec020d0f",
  349. "type": "debug",
  350. "z": "f4a4d8eab7935bc8",
  351. "name": "",
  352. "active": true,
  353. "tosidebar": true,
  354. "console": false,
  355. "tostatus": false,
  356. "complete": "payload",
  357. "targetType": "msg",
  358. "statusVal": "",
  359. "statusType": "auto",
  360. "x": 630,
  361. "y": 380,
  362. "wires": []
  363. },
  364. {
  365. "id": "5426aed100d65d31",
  366. "type": "inject",
  367. "z": "f4a4d8eab7935bc8",
  368. "name": "",
  369. "repeat": "",
  370. "crontab": "",
  371. "once": false,
  372. "onceDelay": 0.1,
  373. "topic": "",
  374. "payload": "",
  375. "payloadType": "date",
  376. "x": 210,
  377. "y": 520,
  378. "wires": [
  379. [
  380. "a911307ea6b68a16"
  381. ]
  382. ]
  383. },
  384. {
  385. "id": "a911307ea6b68a16",
  386. "type": "function",
  387. "z": "f4a4d8eab7935bc8",
  388. "name": "UPDATE",
  389. "func": "var id = 3;\nvar name = 'updateName';\nvar pass = '5555';\nmsg.topic = `UPDATE user SET name='${name}',` +\n `pass='${pass}' WHERE id=${id}`;\nreturn msg;",
  390. "outputs": 1,
  391. "noerr": 0,
  392. "initialize": "",
  393. "finalize": "",
  394. "libs": [],
  395. "x": 340,
  396. "y": 520,
  397. "wires": [
  398. [
  399. "eb4b3bd2a53dbb37",
  400. "d991b7f159d90812"
  401. ]
  402. ]
  403. },
  404. {
  405. "id": "eb4b3bd2a53dbb37",
  406. "type": "mysql",
  407. "z": "f4a4d8eab7935bc8",
  408. "mydb": "51c3503.61936b",
  409. "name": "",
  410. "x": 480,
  411. "y": 520,
  412. "wires": [
  413. [
  414. "c83545834bc01135"
  415. ]
  416. ]
  417. },
  418. {
  419. "id": "c83545834bc01135",
  420. "type": "debug",
  421. "z": "f4a4d8eab7935bc8",
  422. "name": "",
  423. "active": true,
  424. "tosidebar": true,
  425. "console": false,
  426. "tostatus": false,
  427. "complete": "payload",
  428. "targetType": "msg",
  429. "statusVal": "",
  430. "statusType": "auto",
  431. "x": 630,
  432. "y": 520,
  433. "wires": []
  434. },
  435. {
  436. "id": "d991b7f159d90812",
  437. "type": "debug",
  438. "z": "f4a4d8eab7935bc8",
  439. "name": "",
  440. "active": true,
  441. "tosidebar": true,
  442. "console": false,
  443. "tostatus": false,
  444. "complete": "topic",
  445. "targetType": "msg",
  446. "statusVal": "",
  447. "statusType": "auto",
  448. "x": 480,
  449. "y": 600,
  450. "wires": []
  451. },
  452. {
  453. "id": "883fb789f22f352f",
  454. "type": "inject",
  455. "z": "f4a4d8eab7935bc8",
  456. "name": "",
  457. "props": [
  458. {
  459. "p": "payload"
  460. },
  461. {
  462. "p": "topic",
  463. "vt": "str"
  464. }
  465. ],
  466. "repeat": "",
  467. "crontab": "",
  468. "once": false,
  469. "onceDelay": 0.1,
  470. "topic": "",
  471. "payload": "1",
  472. "payloadType": "str",
  473. "x": 210,
  474. "y": 720,
  475. "wires": [
  476. [
  477. "15479540478f4720"
  478. ]
  479. ]
  480. },
  481. {
  482. "id": "fd30c40a7a9d0baf",
  483. "type": "mysql",
  484. "z": "f4a4d8eab7935bc8",
  485. "mydb": "51c3503.61936b",
  486. "name": "",
  487. "x": 480,
  488. "y": 720,
  489. "wires": [
  490. [
  491. "6eb37dd7c809dd01"
  492. ]
  493. ]
  494. },
  495. {
  496. "id": "6eb37dd7c809dd01",
  497. "type": "debug",
  498. "z": "f4a4d8eab7935bc8",
  499. "name": "",
  500. "active": true,
  501. "tosidebar": true,
  502. "console": false,
  503. "tostatus": false,
  504. "complete": "payload",
  505. "targetType": "msg",
  506. "statusVal": "",
  507. "statusType": "auto",
  508. "x": 630,
  509. "y": 720,
  510. "wires": []
  511. },
  512. {
  513. "id": "15479540478f4720",
  514. "type": "template",
  515. "z": "f4a4d8eab7935bc8",
  516. "name": "DELETE",
  517. "field": "topic",
  518. "fieldType": "msg",
  519. "format": "handlebars",
  520. "syntax": "mustache",
  521. "template": "DELETE FROM user WHERE id='{{payload}}'",
  522. "output": "str",
  523. "x": 340,
  524. "y": 720,
  525. "wires": [
  526. [
  527. "fd30c40a7a9d0baf"
  528. ]
  529. ]
  530. }
  531. ]

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/218059?site
推荐阅读
相关标签
  

闽ICP备14008679号