What problem does it solve?
This Skill eliminates manual, error-prone database interactions, inconsistent transaction management, and complex ORM queries. It standardizes data access, making it robust, type-safe, and highly maintainable.
Core Features & Use Cases
- Type-Safe Transactions: Ensures data integrity with automatic session management and reliable commit/rollback mechanisms.
- ORM Best Practices: Guides on efficient querying, N+1 problem avoidance, and clear data access logic using SQLAlchemy.
- Use Case: When building new features requiring database interaction, this Skill provides a ready-to-use, robust pattern, preventing common data access bugs and significantly speeding up development.
Quick Start
Example: Adding a new image record
from src.lorairo.database.schema import Image
from src.lorairo.database.db_repository import ImageRepository
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy import create_engine
Setup (simplified for quick start)
engine = create_engine("sqlite:///:memory:")
Session = scoped_session(sessionmaker(bind=engine))
repo = ImageRepository(Session)
Add an image
new_image = Image(path="/new/image.jpg", phash="newhash")
added_image = repo.add(new_image)
print(f"Added image with ID: {added_image.id}")