Coder Social home page Coder Social logo

Comments (4)

mrcartoonster avatar mrcartoonster commented on June 2, 2024 2

Thank you! This is an AMAZING FastAPI extension.

from fastapi-pagination.

uriyyo avatar uriyyo commented on June 2, 2024 2

I have implemented Tortoise ORM integration and it is available under 0.4.1 version.

To install fastapi-pagination with Tortoise integration please run

pip install -U fastapi-pagination[tortoise]

There is an example of how to integrate fastapi-pagination and Tortoise:

from typing import Any
import uvicorn
from faker import Faker
from fastapi import Depends, FastAPI
from pydantic import BaseModel
from tortoise import Model
from tortoise.contrib.fastapi import register_tortoise
from tortoise.fields import IntField, TextField
from fastapi_pagination import Page, pagination_params
from fastapi_pagination.ext.tortoise import paginate
faker = Faker()
class User(Model):
id = IntField(pk=True)
name = TextField(null=False)
email = TextField(null=False)
class UserIn(BaseModel):
name: str
email: str
class UserOut(UserIn):
id: int
class Config:
orm_mode = True
app = FastAPI()
register_tortoise(
app,
db_url="sqlite://:memory:",
modules={"models": [__name__]},
generate_schemas=True,
)
@app.on_event("startup")
async def on_startup() -> None:
for _ in range(100):
await User.create(
name=faker.name(),
email=faker.email(),
)
@app.post("/users", response_model=UserOut)
async def create_user(user_in: UserIn) -> Any:
return await User.create(**user_in.dict())
@app.get("/users", response_model=Page[UserOut], dependencies=[Depends(pagination_params)])
async def get_users() -> Any:
return await paginate(User)
if __name__ == "__main__":
uvicorn.run("pagination_tortoise:app")

In case of any questions or issues feel free to reopen this issue.

from fastapi-pagination.

uriyyo avatar uriyyo commented on June 2, 2024

Hi, @mrcartoonster

Definitely yes!
Tortoise is the next thing which I want to integrate with fastapi-pagination

from fastapi-pagination.

mrcartoonster avatar mrcartoonster commented on June 2, 2024

Cool! I'll let you know if I run into any issues. I'll try it out by the end of today.

from fastapi-pagination.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.