Fixing some issues found with query while testing.

This commit is contained in:
mike12345567 2021-10-13 13:22:13 +01:00
parent b46a945fc4
commit dcb334b564
1 changed files with 8 additions and 7 deletions

View File

@ -29,9 +29,6 @@ function formatResponse(resp) {
resp = { response: resp } resp = { response: resp }
} }
} }
if (!Array.isArray(resp)) {
resp = [resp]
}
return resp return resp
} }
@ -49,15 +46,19 @@ async function runAndTransform(
rows = runner.execute() rows = runner.execute()
} }
// get all the potential fields in the schema // needs to an array for next step
let keys = rows.flatMap(Object.keys) if (!Array.isArray(rows)) {
rows = [rows]
}
// map into JSON if just raw primitive here // map into JSON if just raw primitive here
if (keys.length === 0) { if (rows.find(row => typeof row !== "object")) {
rows = rows.map(value => ({ value })) rows = rows.map(value => ({ value }))
keys = ["value"]
} }
// get all the potential fields in the schema
let keys = rows.flatMap(Object.keys)
return { rows, keys } return { rows, keys }
} }