Skip to content

6. Pagination

cjlotto edited this page Aug 12, 2023 · 1 revision
def get_question_list(db: Session, skip: int = 0, limit: int = 10):
    _question_list = db.query(Question).order_by(Question.create_date.desc())
    total = _question_list.count()
    question_list = _question_list.offset(skip).limit(limit).all()
    return total, question_list
  • skip : 조회 데이터의 시작 위치
  • limit : 시작 위치(skip)부터 가져올 데이터양
class QuestionList(BaseModel):
    total: int = 0
    question_list: list[Question] = []
  • question_schema.py
@router.get("/list", response_model=list[question_schema.QuestionList])
def question_list(db: Session = Depends(get_db), page: int = 0, size: int = 10):
    total, _question_list = question_crud.get_question_list(
        db, skip=page * size, limit=size
    )
    return {"total": total, "question_list": _question_list}
  • question_router.py
📚 Kubernetes

Kubernetes

따배쿠

📕 Ingress

ETC

📕 Ingress

📚 Nginx

Nginx

📝 선수 지식

📝 What is Nginx ?

📝 How to use Nginx

📚 NodeJS

NodeJS

📚 FastAPI

FastAPI

📝 Pybo Wikibooks

📚 Elastic Search

Elastic Search

ETC

📚 Reference

📚 DB

DB

📂 SQL

📂 Redis - NoSQL

📚 AWS

AWS

📕 IAM

📚 Docker

Docker

📚 Helm

Helm

📚 Deep Learning

Deep Learning

Nocode

📚 Coding Test

Coding Test

📕 Nocode

🔖 Array

🔖 String

📕 Tip

Clone this wiki locally