Manipulate results to group by value

Options

Hello fellow Xano enthousiasts,

I am stuck with manipulating results from a database to make it easily usable for my frontend. The current result I am getting is attached as an image below. What I would like is to group all the results by category as a separate array.

So basically an array for 'Time' would contain all the rows from the database where the key "category" equals 'Time'.

Does anyone have an idea on how to achieve this?

Thanks and have a wonderful day!


Best Answer

Answers

  • Robert Freericks
    Options

    @Michael Udinski Thanks a lot for the suggestion! It did get me in the right direction, but I can't get the desired result completely to make it usable on my front-end. I am certain Xano can do this but, perhaps you have one more suggestion to go from the screenshot in the my question to a result similar like the one below.

    The "key" is quite obsolete, but it seemed like an easy way for me to do get further. Any help is much appreciated!

    Kind regards,

    Robert


  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Rather than using SQL aggregates per se, I'd loop over the results from your query in the function stack and build out a new object containing the results you are looking for. Then return that new object. That kind of data transformation is what Xano does well.

    In functional programming this would be called a reducer. (No-code doesn't mean computer science can't help us!)

    This is the kind of hard problem we work on in our State Change Pro office hours on a daily basis. It's mostly a matter of the mental model of looping over the data and accumulating into that output variable.