README in Spanish
Architected bidirectional one-to-many relationships with lazy loading and cascade operations. Implemented complex aggregation queries using func.count(), group_by(), and subqueries. Designed session management with proper commit and rollback transaction handling. Built a data analysis pipeline with status distribution, category-based metrics, and trend analysis. Automated report generation with JSON serialization and metadata tagging. Tech stack: SQLAlchemy 2.0+, Python 3.14, SQLite3.
Advanced ORM demonstrations showcasing professional database operations, relationships, and complex queries using SQLAlchemy 2.0+.
-
Relational Models: Definition of
BusinessOperationandOperationDetailentities with bidirectional one-to-many relationships. -
Full CRUD: Create, read, and update operations with exception and transaction handling.
-
Advanced Queries: Filtering by type, retrieval with relationships, and complex aggregations.
-
Dynamic Summaries: Generation of statistics on operations (sum, average, max, min).
-
Data Cleansing: Function to delete old records by date.
-
Session Management: Proper handling of sessions, commits, and rollbacks.
- SQLAlchemy 2.0+ – ORM y query builder.
- SQLite – Lightweight, configurable database.
- Python 3.14+
create_operation()– Create an operation with associated details.get_operations_by_type()– Filter operations by type.get_operation_with_details()– Get an operation with loaded relationships.update_operation_status()– Update the status with automatic timestamp.get_operations_summary()– Generate a summary with statistics and distributions.cleanup_old_operations()– Delete old records based on age.
from main import DatabaseManager
# Initialize
db = DatabaseManager()
# Create operation
operation = db.create_operation(
"OP_001",
"logistics",
1250.50,
details={"priority": "high", "location": "Lima"}
)
# Get summary
summary = db.get_operations_summary()
print(f"Total operaciones: {summary['total_operations']}")
# Update status
db.update_operation_status(operation.id, "completed")
# Log out
db.close()uv sync
uv run python sqlalchemy_operations.py
uv run pytest -v