nodejs sql get one to many relationship as array
-- use json_agg
SELECT i.id as interview_id, i.board, i.time_taken, i.notes, i.interview_date,
u.id as user_id, u.first_name, u.last_name, u.state, u.district, u.optional,
j.name as job,
json_agg(json_build_object('question', q.question, 'answer', q.answer, 'member', q."member", 'order', q."order")) as questions
FROM interview i LEFT JOIN
question q
ON q.interview_id = i.id JOIN
users u
ON i.user_id = u.id JOIN
user_jobs uj
ON uj.user_id = u.id JOIN
job j
ON uj.job_id = j.id
GROUP BY u.id, i.id, j.name