Quick updates to make sure mySQL works with automations.

This commit is contained in:
mike12345567 2021-06-18 13:24:29 +01:00
parent 40e06cc5d1
commit eb2cf1afa6
2 changed files with 18 additions and 10 deletions

View File

@ -22,19 +22,26 @@ function inputProcessing(row, table) {
return newRow 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) { function outputProcessing(rows, table) {
// if no rows this is what is returned? Might be PG only // if no rows this is what is returned? Might be PG only
if (rows[0].read === true) { if (rows[0].read === true) {
return [] return []
} }
const primary = table.primary
for (let row of rows) { for (let row of rows) {
// build id array row._id = generateIdForRow(row, table)
let idParts = []
for (let field of primary) {
idParts.push(row[field])
}
row._id = generateRowIdField(idParts)
row.tableId = table._id row.tableId = table._id
row._rev = "rev" row._rev = "rev"
} }
@ -89,8 +96,6 @@ async function handleRequest(
} }
// clean up row on ingress using schema // clean up row on ingress using schema
filters = buildFilters(id, filters, table) 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) row = inputProcessing(row, table)
if ( if (
operation === DataSourceOperation.DELETE && operation === DataSourceOperation.DELETE &&
@ -114,7 +119,7 @@ async function handleRequest(
body: row, body: row,
// pass an id filter into extra, purely for mysql/returning // pass an id filter into extra, purely for mysql/returning
extra: { extra: {
idFilter: buildFilters(id, {}, table), idFilter: buildFilters(id || generateIdForRow(row, table), {}, table),
} }
} }
// can't really use response right now // can't really use response right now

View File

@ -180,6 +180,9 @@ class MySQLIntegration extends Sql {
} }
async getReturningRow(json) { async getReturningRow(json) {
if (!json.extra.idFilter) {
return {}
}
const input = this._query({ const input = this._query({
endpoint: { endpoint: {
...json.endpoint, ...json.endpoint,