Automated Action a030964e07 Implement REST API with FastAPI and SQLite
- Set up project structure and dependencies
- Implement database models with SQLAlchemy
- Set up Alembic migrations
- Create FastAPI application with CORS support
- Implement API endpoints (CRUD operations)
- Add health check endpoint
- Update README with setup and usage instructions
2025-06-03 12:23:52 +00:00

18 lines
719 B
Python

from typing import List, Optional
from sqlalchemy.orm import Session
from app.models.item import Item
from app.schemas.item import ItemCreate, ItemUpdate
from app.crud.base import CRUDBase
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
def get_by_name(self, db: Session, *, name: str) -> Optional[Item]:
"""Get an item by name."""
return db.query(Item).filter(Item.name == name).first()
def get_active(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Item]:
"""Get active items with pagination."""
return db.query(Item).filter(Item.is_active).offset(skip).limit(limit).all()
# Create an instance for importing in other modules
item = CRUDItem(Item)