attachment.py 586 B

123456789101112131415161718192021222324252627282930
  1. """附件元数据 CRUD"""
  2. from typing import Optional
  3. from sqlalchemy.orm import Session
  4. from app.models.business import Attachment
  5. def create_attachment(
  6. db: Session,
  7. *,
  8. file_name: str,
  9. object_key: str,
  10. url: str,
  11. size: int = 0,
  12. biz_type: Optional[str] = None,
  13. biz_id: Optional[str] = None,
  14. ) -> Attachment:
  15. row = Attachment(
  16. file_name=file_name,
  17. object_key=object_key,
  18. url=url,
  19. size=size,
  20. biz_type=biz_type,
  21. biz_id=biz_id,
  22. )
  23. db.add(row)
  24. db.commit()
  25. db.refresh(row)
  26. return row