PostgreSQL and nodejs/pg, return nested JSON
问题 I'm using PostgreSQL with nodejs and pg. Everything works fine, but I want to output a result from PostgreSQL as a nested json - as if I was working with MongoDB or similar. My 2 tables from PostgreSQL are: portfolio (id int, name text) cars (portfolio_id int, name text); Is there a "correct" way of returning a JSON object with the following structure: { { name: 'Portfolio #1', cars: { name: 'Car #1', name: 'Car #2' }, { name: 'Portfolio #2', cars: { name: 'Car #3' } } My general way of