
- Fix code linting issues - Update README with detailed documentation - Configure database paths for the current environment - Create necessary directory structure The News Aggregation Service is now ready to use with FastAPI and SQLite.
24 lines
637 B
Python
24 lines
637 B
Python
from sqlalchemy import Column, DateTime
|
|
from sqlalchemy.ext.declarative import declared_attr
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
class TimestampMixin:
|
|
"""Mixin that adds created_at and updated_at columns to models."""
|
|
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(
|
|
DateTime,
|
|
default=datetime.utcnow,
|
|
onupdate=datetime.utcnow,
|
|
nullable=False
|
|
)
|
|
|
|
|
|
class TableNameMixin:
|
|
"""Mixin that automatically sets the table name based on the class name."""
|
|
|
|
@declared_attr
|
|
def __tablename__(cls) -> str:
|
|
return cls.__name__.lower() |