I often (50% of the time) flatten my query result as I find them much easier to work with flat. I also find that there dont seem to be many downsides as most retool components treat default and flat daa the same. I use this code in the transform section to flatten, but it would be great if this would be a default toggle, rather than me having this code snippet saved in a note for reuse
// Step 1: Flatten data into an array of objects
const flatData = Array.from(
{ length: Object.values(data)[0]?.length || 0 }, // Determine the number of rows from the first key
(_, index) => {
const record = {};
// Iterate over each key in the data object and map its values to the record
Object.keys(data).forEach(key => {
record[key] = data[key][index];
});
return record;
}
);
return flatData;