3 ms·
FastAPI doesn’t come with an ORM out of the box. There’s https://sqlmodel.tiangolo.com/ https://sqlmodel.tiangolo.com/ which wraps SQLAlchemy and allows definin
by barefeg 4y ago
FastAPI doesn’t come with an ORM out of the box. There’s https://sqlmodel.tiangolo.com/ https://sqlmodel.tiangolo.com/ which wraps SQLAlchemy and allows defining the database models with pydantic-like classes.
For me neither Django nor SQLAlcjemy hit the right spot when trying to define “pure” domain models that have no dependency (I.e. no ORM information). For that I created a repository pattern approach that converts “domain mode operations” into SQLModel query operations via filter specifications (https://martinfowler.com/apsupp/spec.pdf https://martinfowler.com/apsupp/spec.pdf).
The result is that I always need to define 2 models: one is my pure domain model and another is a “table model” (defined in SQLAlchemy) along with a mapping between the two (for cases where there’s no 1-to-1 trivial mapping between their fields). Also making some of the SQLAlchemy magic (for example back propagating relational attributes) is messy.
But if you want to produce some quick applications I think SQLModel+FastAPI works quite well. I don’t think is as mature as Django though.