Skip to content

FastAPI: Utilize FastAPI's SQLModel & Databases Plugins #298

@sync-by-unito

Description

@sync-by-unito

FastAPI Database Libraries

The implementation of FastAPI sister libraries SQLModel and Databases is highly optional. These libraries intend to improve developer experience; they are not required, nor do they offer significant performance benefits.

1. https://sqlmodel.tiangolo.com/

Extends SQLAlchemy’s “model” object with Pydantic syntax to avoid code duplication between Models and Schemas. Such duplication is otherwise nearly inevitable per FastAPI’s default pattern of defining SQLAlchemy https://fastapi.tiangolo.com/tutorial/sql-databases/?h=database#create-sqlalchemy-models-from-the-base-class alongside https://fastapi.tiangolo.com/tutorial/sql-databases/?h=database#create-sqlalchemy-models-from-the-base-class. Such duplication already exists in database/models.py and database/schemas.py, respectively.

2. https://fastapi.tiangolo.com/how-to/async-sql-encode-databases/?h=database#import-and-set-up-databases

FastAPI’s databases library allows predefined SQLAlchemy database models to build API responses defined solely via ORM queries. This is somewhat similar to the native Django behavior of defining model-based views (such as /list/[MODEL_NAME].

┆Issue is synchronized with this Jira Story

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions