Code Room
Code reviewMediumcr-g292
Subject N plus one queriesLevel Mid–Senior~18 minCommon in Databases & SQL interviewsIndustries Software development, Technology

Question

Review this JavaScript service that builds a dashboard of teams with their member counts.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewjavascript
async function teamsWithCounts(orgId) {    const teams = await db.query("SELECT id, name FROM teams WHERE org_id = $1", [orgId]);    const result = [];    for (const t of teams) {        const c = await db.query("SELECT COUNT(*) AS n FROM members WHERE team_id = $1", [t.id]);        result.push({ ...t, members: c[0].n });    }    return result;}
Run or narrate your approach, then ask the coach.