Browse Source

Fixing some issues found with query while testing.

master
mike12345567 5 years ago
parent
commit
cd1f48b920
  1. 15
      packages/server/src/api/controllers/query.js

15
packages/server/src/api/controllers/query.js

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

Loading…
Cancel
Save