Skip to content

[Go] Implement N+1 Query Solution with JOINs #302

@davideme

Description

@davideme

Task

Implement the ?include= query parameter for eager loading in Go/sqlc.

Endpoints

  • GET /buildings with ?include=rooms or ?include=rooms.lamps
  • GET /buildings/{id} with ?include=rooms.lamps
  • GET /buildings/{id}/rooms with ?include=lamps
  • GET /rooms/{id} with ?include=lamps,building

Functional Requirement

Must minimize database queries regardless of the number of entities returned.

Implementation Hints

  • Write SQL queries with JOINs in sqlc
  • Create separate query variants for different include combinations
  • Or use dynamic query building with proper JOIN clauses
  • Map flattened results back to nested structs

Acceptance Criteria

  • ?include=rooms returns buildings with nested rooms
  • ?include=rooms.lamps returns buildings with rooms and lamps
  • Query count does not increase with number of buildings (verify with SQL logging)

Parent Issue

Relates to #289

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions