
- Setup FastAPI project structure with main.py and requirements.txt - Implement SQLAlchemy ORM with SQLite database - Create Item model with CRUD operations - Implement health endpoint for monitoring - Setup Alembic for database migrations - Add comprehensive documentation in README.md - Configure Ruff for code linting
27 lines
706 B
Python
27 lines
706 B
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.item import Item
|
|
from app.schemas.item import ItemCreate, ItemUpdate
|
|
|
|
|
|
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
|
|
def get_by_title(self, db: Session, *, title: str) -> Optional[Item]:
|
|
return db.query(Item).filter(Item.title == title).first()
|
|
|
|
def get_multi_active(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Item]:
|
|
return (
|
|
db.query(Item)
|
|
.filter(Item.is_active == True) # noqa: E712
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
item = CRUDItem(Item)
|