__init__.py 503 B

12345678910111213141516171819202122
  1. from app.models.database import SessionLocal
  2. # Dependency
  3. def get_db():
  4. try:
  5. db = SessionLocal()
  6. yield db
  7. finally:
  8. db.close()
  9. async def get_page(
  10. page: int = 1, size: int = 10
  11. ):
  12. return {"page": page, "size": size}
  13. def page_help(data, page: int, size: int, total: int = None):
  14. if total is None:
  15. total = len(data)
  16. data = data[(page - 1) * size:page * size]
  17. return {"item":data, "extra_data": {"page":page, "size":size, "total":total}}