Install any skill in seconds. Free to start, no credit card required.
Get Started Free →This skill covers patterns for managing database sessions and models. Trigger: Load when working with database interactions.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | -28% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -5% | 0% |
| case-03 | ✗→✓ | ▲ Improved | -51% | 0% |
| case-07 | ✗→✓ | ▲ Improved | -53% | 0% |
| case-08 | ✗→✓ | ▲ Improved | -39% | 0% |
<!-- L1:START -->
This skill covers patterns for managing database sessions and models.
Trigger: Load when working with database interactions. <!-- L1:END -->
<!-- L2:START -->
| Task | Pattern | |------|---------| | Create a database session | get_db() | | Define a database model | Base |
get_db() to create a session for database operations.Base to define your database models.<!-- L2:END -->
<!-- L3:START -->
Use get_db() to create a session for database operations, ensuring proper management of database connections.
pythonfrom apps.server.app.models.database import get_db async def some_database_operation(): async with get_db() as session: # Perform database operations pass
Utilize Base to define your database models, which will serve as the foundation for your ORM mappings.
pythonfrom apps.server.app.models.database import Base from sqlalchemy import Column, Integer, String class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True, index=True) name = Column(String, index=True)
bashpython -m alembic upgrade head
Using raw SQL queries bypasses the ORM and can lead to security vulnerabilities and maintenance issues.
python# BAD async def raw_query(): await db.execute("SELECT * FROM users")
<!-- L3:END -->
Other measured skills in the registry, with their headline benchmark lift.