API pagination with FastAPI and SQLAlchemy

  Рет қаралды 3,356

microapis

microapis

Күн бұрын

Пікірлер: 4
@ljptech
@ljptech 8 ай бұрын
It was really nice to meet you today Jose! I will cheer for you business and your very bright future ahead.
@microapis
@microapis 8 ай бұрын
Thank you was a great pleasure meeting you too and I really enjoyed our conversation! Wish you the very best with your projects too and looking forward to seeing them grow. Hope we can see each other again!
@grahortarg9933
@grahortarg9933 10 ай бұрын
I still have a question - how to do count with filters?
@microapis
@microapis 7 ай бұрын
Thank you for your question! You'd follow the same approach shown in the video, only applying the filters first. Here's an example: @router.get("/jobs", response_model=ListJobs) def list_jobs(contract_type: ContractTypeEnum | None = None,): with session_maker() as session: query = select(Job) if contract_type: query = query.where(Job.contract_type == contract_type.value) count = session.execute( select(func.count()).select_from(query.subquery()) ).scalar_one() This endpoint returns a list of jobs and allows you to filter by contract type. The filter is optional and None by default, so first we check if it's set, and if so, we apply the filter to the query. Once we've filtered the result set, we count the items. Hope this helps, if you have any more questions please let me know!
SQLModel + FastAPI: Say Goodbye to Repetitive Database Code
19:50
Web API Pagination | Offset-based vs Cursor-based
11:03
Ambient Coder
Рет қаралды 48 М.
Counter-Strike 2 - Новый кс. Cтарый я
13:10
Marmok
Рет қаралды 2,8 МЛН
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
Wednesday VS Enid: Who is The Best Mommy? #shorts
0:14
Troom Oki Toki
Рет қаралды 50 МЛН
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 226 М.
Пагинация в БД без offset. Работаем с запросами
24:52
Create custom middleware with FastAPI
19:55
microapis
Рет қаралды 1,5 М.
Event-Driven Architecture (EDA) vs Request/Response (RR)
12:00
Confluent
Рет қаралды 184 М.
SQLAlchemy Makes Using Python Databases EASY
19:08
Eric Roby
Рет қаралды 8 М.
Want to build a good API? Here's 5 Tips for API Design.
10:57
CodeOpinion
Рет қаралды 213 М.
How To Create a Python API With FastAPI - Full Tutorial
25:39
Tech With Tim
Рет қаралды 58 М.
Counter-Strike 2 - Новый кс. Cтарый я
13:10
Marmok
Рет қаралды 2,8 МЛН