From eb2cf1afa6b2382ece8931e7d1de94e9cc981f12 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 18 Jun 2021 13:24:29 +0100 Subject: [PATCH] Quick updates to make sure mySQL works with automations. --- .../src/api/controllers/row/external.js | 25 +++++++++++-------- packages/server/src/integrations/mysql.js | 3 +++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/server/src/api/controllers/row/external.js b/packages/server/src/api/controllers/row/external.js index 323e3525d2..cec58351a8 100644 --- a/packages/server/src/api/controllers/row/external.js +++ b/packages/server/src/api/controllers/row/external.js @@ -22,19 +22,26 @@ function inputProcessing(row, table) { return newRow } +function generateIdForRow(row, table) { + if (!row) { + return + } + const primary = table.primary + // build id array + let idParts = [] + for (let field of primary) { + idParts.push(row[field]) + } + return generateRowIdField(idParts) +} + function outputProcessing(rows, table) { // if no rows this is what is returned? Might be PG only if (rows[0].read === true) { return [] } - const primary = table.primary for (let row of rows) { - // build id array - let idParts = [] - for (let field of primary) { - idParts.push(row[field]) - } - row._id = generateRowIdField(idParts) + row._id = generateIdForRow(row, table) row.tableId = table._id row._rev = "rev" } @@ -89,8 +96,6 @@ async function handleRequest( } // clean up row on ingress using schema filters = buildFilters(id, filters, table) - // get the id after building filters, but before it is removed from the row - id = id || (row ? row._id : null) row = inputProcessing(row, table) if ( operation === DataSourceOperation.DELETE && @@ -114,7 +119,7 @@ async function handleRequest( body: row, // pass an id filter into extra, purely for mysql/returning extra: { - idFilter: buildFilters(id, {}, table), + idFilter: buildFilters(id || generateIdForRow(row, table), {}, table), } } // can't really use response right now diff --git a/packages/server/src/integrations/mysql.js b/packages/server/src/integrations/mysql.js index b1a661cfb7..e8e75d6aad 100644 --- a/packages/server/src/integrations/mysql.js +++ b/packages/server/src/integrations/mysql.js @@ -180,6 +180,9 @@ class MySQLIntegration extends Sql { } async getReturningRow(json) { + if (!json.extra.idFilter) { + return {} + } const input = this._query({ endpoint: { ...json.endpoint,