crud_user.py 711 B

12345678910111213141516171819202122232425
  1. from sqlalchemy.orm import Session
  2. from app.models.user import User
  3. from app.schemas.user import UserCreate
  4. def get_user(db: Session, user_id: int):
  5. return db.query(User).filter(User.id == user_id).first()
  6. def get_user_by_email(db: Session, email: str):
  7. return db.query(User).filter(User.email == email).first()
  8. def get_users(db: Session, skip: int = 0, limit: int = 100):
  9. return db.query(User).offset(skip).limit(limit).all()
  10. def create_user(db: Session, user: UserCreate):
  11. fake_hashed_password = user.password + "notreallyhashed"
  12. db_user = User(email=user.email, hashed_password=fake_hashed_password)
  13. db.add(db_user)
  14. db.commit()
  15. db.refresh(db_user)
  16. return db_user