-
-
Save AdamOswald/88b36f79fa803f0072b6f265c5b77016 to your computer and use it in GitHub Desktop.
Revisions
-
dineshkumarkb created this gist
Sep 20, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ from fastapi_pagination import Page, paginate, add_pagination from pydantic import BaseModel from fastapi import FastAPI from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.orm import sessionmaker, declarative_base from datetime import date app = FastAPI(title=" A simple pagination learning exercise", debug=True) add_pagination(app) class Employee(Base): __tablename__ = "employee" empid = Column(Integer, primary_key=True) empname = Column(String) dept = Column(Integer) location = Column(String) dob = Column(Date) class EmployeeOut(BaseModel): empid: int empname: str dept: int location: str dob: date class Config: orm_mode = True @app.get(path="/api/employees/all", name="Gets all employees", response_model=Page[EmployeeOut]) async def get_all_employees(): conn = connect_to_db() results = conn.query(Employee).all() return paginate(results)