Ctrl + k

or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/sqlmodel@0.0.x
tile.json

tessl/pypi-sqlmodel

tessl install tessl/pypi-sqlmodel@0.0.0

SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.

Agent Success

Agent success rate when using this tile

85%

Improvement

Agent success rate improvement when using this tile compared to baseline

1x

Baseline

Agent success rate without this tile

85%

task.mdevals/scenario-3/

Employee Management System with Role-Based Polymorphism

Description { .description }

Create an employee management system that uses polymorphic inheritance to model different types of employees. The system should store all employees in a single database table with a discriminator field to identify the specific employee type.

Requirements { .requirements }

  1. Create a base Employee model with common attributes:

    • id: Auto-incrementing integer primary key
    • name: String field for the employee's name
    • email: String field for the employee's email address
    • salary: Float field for the base salary
  2. Create two specialized employee types that inherit from the base Employee model:

    • Engineer: Adds a programming_language string field
    • Manager: Adds an department string field
  3. Implement single-table inheritance where all employee types are stored in the same database table using a discriminator column to identify the type.

  4. Create a database with SQLite, initialize the tables, and implement the following operations:

    • Add at least 2 engineers and 2 managers to the database
    • Query and retrieve all employees
    • Query and retrieve only engineers
    • Query and retrieve only managers
  5. Print the results showing that the polymorphic queries work correctly, displaying each employee's type-specific attributes.

Test Cases { .test-cases }

Test 1: Create and query engineers @test

# test_employee.py
from employee import Employee, Engineer, Manager, engine
from sqlmodel import Session, select

def test_create_and_query_engineers():
    with Session(engine) as session:
        # Create engineers
        eng1 = Engineer(name="Alice Smith", email="alice@example.com", salary=95000.0, programming_language="Python")
        eng2 = Engineer(name="Bob Jones", email="bob@example.com", salary=98000.0, programming_language="Go")

        session.add(eng1)
        session.add(eng2)
        session.commit()

        # Query engineers
        statement = select(Engineer)
        engineers = session.exec(statement).all()

        assert len(engineers) >= 2
        assert all(isinstance(e, Engineer) for e in engineers)
        assert any(e.programming_language == "Python" for e in engineers)

Test 2: Create and query managers @test

# test_employee.py
from employee import Employee, Engineer, Manager, engine
from sqlmodel import Session, select

def test_create_and_query_managers():
    with Session(engine) as session:
        # Create managers
        mgr1 = Manager(name="Carol White", email="carol@example.com", salary=110000.0, department="Engineering")
        mgr2 = Manager(name="David Brown", email="david@example.com", salary=105000.0, department="Sales")

        session.add(mgr1)
        session.add(mgr2)
        session.commit()

        # Query managers
        statement = select(Manager)
        managers = session.exec(statement).all()

        assert len(managers) >= 2
        assert all(isinstance(m, Manager) for m in managers)
        assert any(m.department == "Engineering" for m in managers)

Test 3: Query all employees polymorphically @test

# test_employee.py
from employee import Employee, Engineer, Manager, engine
from sqlmodel import Session, select

def test_query_all_employees():
    with Session(engine) as session:
        # Query all employees
        statement = select(Employee)
        all_employees = session.exec(statement).all()

        assert len(all_employees) >= 4

        # Verify we have both types
        engineers = [e for e in all_employees if isinstance(e, Engineer)]
        managers = [e for e in all_employees if isinstance(e, Manager)]

        assert len(engineers) >= 2
        assert len(managers) >= 2

Expected Output { .expected-output }

Your program should produce output similar to:

Engineers:
- Alice Smith (alice@example.com) - Salary: $95000.00 - Language: Python
- Bob Jones (bob@example.com) - Salary: $98000.00 - Language: Go

Managers:
- Carol White (carol@example.com) - Salary: $110000.00 - Department: Engineering
- David Brown (david@example.com) - Salary: $105000.00 - Department: Sales

All Employees:
- Engineer: Alice Smith (alice@example.com)
- Engineer: Bob Jones (bob@example.com)
- Manager: Carol White (carol@example.com)
- Manager: David Brown (david@example.com)

Constraints { .constraints }

  • Use SQLite as the database engine
  • Use single-table inheritance (all employees in one table)
  • Ensure proper polymorphic configuration for queries to return the correct subclass instances

Entry Points { .entry-points }

employee.py { .entry-point }

Main implementation file containing the Employee, Engineer, and Manager models, database setup, and demonstration code.

Dependencies { .dependencies }

sqlmodel { .dependency }

Provides ORM and data validation support for SQL databases.