0

I have one select query in Objections JS(NodeJs). That will return few fields. I need to modify the result. Suppose we have got below json from the response of the query.

{
   group_id, 
   group_name,
   link,
   created,
   user_id
}

I need to update this response like below with the use of the loop of the.

{
   group: {
      id, 
      name,
   },
   link,
   created,
   user_id
}

Is there any option in objections to updating our result like this? Please help me with this concern.

Rav's Patel
  • 743
  • 6
  • 22

1 Answers1

0

You can do like this for getting the response as you mentioned above.

SELECT 
   JSON_OBJECT('id', group_id, 'name', group_name) as group, 
   link,
   created,
   user_id FROM table_name;

Anjusha T Shaju
  • 106
  • 1
  • 9