I am trying to receive all of the players under a certain team along with the team's id.
Here is my query:
SELECT player.team_id, team.name, player.first_name, player.last_name FROM player, team WHERE player.team_id = team.id AND player.league = "League 1";
I am taking the result (stored in teams) and sending it to my client by doing this:
res.send({
        success: true,
        teams: teams
      });
Here is what it returns when I reach its endpoint:
I want to reformat this date to where I get one field for each unique team. It should have a players field (array) inside so I can access the names of each player part of the team. Does anyone know how I can manipulate this data to that format?
So for example, for this data set, inside the teams object, there would only be one field named "Warriors" with a players array that has all of those people's name inside of it.
I tried following the answer, but now it's just returning it as a string, not an actual object.

