
- Set up project structure with FastAPI - Configure SQLite database with SQLAlchemy - Set up Alembic for migrations - Create Item model and schema - Implement CRUD operations - Add health endpoint generated with BackendIM... (backend.im)
20 lines
619 B
Python
20 lines
619 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_active_items(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Item]:
|
|
return db.query(Item).filter(Item.is_active == True).offset(skip).limit(limit).all()
|
|
|
|
|
|
item = CRUDItem(Item) |