crud_item.py 430 B

12345678910111213141516
  1. from sqlalchemy.orm import Session
  2. from app.models.item import Item
  3. from app.schemas.item import ItemCreate
  4. def get_items(db: Session, skip: int = 0, limit: int = 100):
  5. return db.query(Item).offset(skip).limit(limit).all()
  6. def create_user_item(db: Session, item: ItemCreate, user_id: int):
  7. db_item = Item(**item.dict(), owner_id=user_id)
  8. db.add(db_item)
  9. db.commit()
  10. db.refresh(db_item)
  11. return db_item