SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.
Overall
score
85%
Build a hero team management system that efficiently loads hero-team relationships using different database query strategies.
Create a system that manages heroes and their teams with optimized relationship loading.
Define two database models:
Hero with fields: id (primary key), name (string), secret_name (string), and a relationship to teamTeam with fields: id (primary key), name (string), headquarters (string), and a relationship to heroesImplement the following functions in hero_manager.py:
get_hero_with_team_lazy(session, hero_id: int) - Retrieve a hero by ID. The team should be loaded on-demand when accessed (default behavior, no eager loading)get_team_with_heroes_joined(session, team_id: int) - Retrieve a team with all its heroes loaded in a single query using a SQL JOINget_all_teams_with_heroes_selectin(session) - Retrieve all teams and efficiently load their heroes in a second separate SELECT queryget_team_heroes_count(session, team_id: int) -> int - Return the count of heroes in a specific teamEach function should return the appropriate model instance(s) with relationships accessible as specified.
@generates
Provides SQL database operations with ORM and data validation support.
Install with Tessl CLI
npx tessl i tessl/pypi-sqlmodeldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10