4 ms·
Have you written it with an ORM backed app? I’m curious if you put the business logic on the Pydantic models and keep the ORM small, or put the logic on the ORM
by travisjungroth 6y ago
Have you written it with an ORM backed app? I’m curious if you put the business logic on the Pydantic models and keep the ORM small, or put the logic on the ORM and treat Pydantic like a serializer. Personally, I’d rather work with Pydantic models than ORM.
- sandGorgon 6y agothere's a way to autogenerate pydantic and ORM (sqlalchemy) models from the same python dataclasses. here's a fully functional gist - https://gist.github.com/sandys/671b8b86ba913e6436d4cb22d04b135f https://gist.github.com/sandys/671b8b86ba913e6436d4cb22d04b1...
- madkat 6y agoWe use SQLAlchemy as the ORM layer, but it's very small and most of the work is done with the Pydantic models. It works quite nicely, despite that we loose change tracking, but SQLAlchemy got us covered with merging models.
- polyrand 6y agoI don’t use ORMs. For bigger apps, I use asyncpg and map the results to Pydantic objects. I write raw SQL and keep Pydantic objects as the “source of truth” throughout my app.