From fdfdbb17b7ea7e82f4bb80abfd14f0f058a90bfd Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 23 Apr 2021 22:23:16 +0100 Subject: [PATCH] Fix mysql multiple return queries type to close #797 --- storage/mysql/68-mysql.js | 11 ++++++++++- storage/mysql/package.json | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/storage/mysql/68-mysql.js b/storage/mysql/68-mysql.js index df425548..39b727be 100644 --- a/storage/mysql/68-mysql.js +++ b/storage/mysql/68-mysql.js @@ -155,7 +155,16 @@ module.exports = function(RED) { msg.payload = JSON.parse(JSON.stringify(rows)); } else if (rows.constructor.name === "Array") { - msg.payload = rows.map(v => Object.assign({}, v)); + if (rows[0] && rows[0].constructor.name === "RowDataPacket") { + msg.payload = rows.map(v => Object.assign({}, v)); + } + else if (rows[0] && rows[0].constructor.name === "Array") { + if (rows[0][0] && rows[0][0].constructor.name === "RowDataPacket") { + msg.payload = rows.map(v => v.map(w => Object.assign({}, w))); + } + else { msg.payload = rows; } + } + else { msg.payload = rows; } } else { msg.payload = rows; } send(msg); diff --git a/storage/mysql/package.json b/storage/mysql/package.json index fdeedac3..19440fac 100644 --- a/storage/mysql/package.json +++ b/storage/mysql/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-mysql", - "version": "0.1.7", + "version": "0.1.8", "description": "A Node-RED node to read and write to a MySQL database", "dependencies": { "mysql": "^2.18.1"