Comment by Noumenon72
17 hours ago
I'm using SQLAlchemy, Alembic, and FastAPI. Either this is for someone much more advanced than me, or it could use some examples showing "This is clunky in SQLAlchemy and easy in Advanced-Alchemy." When you look at SQLModel[1] from FastAPI, which I did adopt, it does a much better job at promising "this will make your life easier".
I don't like SQLModel for the simple reason that it muddles boundaries between different parts of the application. I suppose when you have a pure CRUD app it's ok, but anytime you want to handle ORM objects and apply some business logic; you'll want to cleanly separate those from what you send and receive from your API.
Right. I have to wonder how often people are building "APIs" that are just direct CRUD interfaces to SQL DBs. SQLModel seems like taking DRY too seriously. I get it, SQLAlchemy models and Pydantic models look very similar, but they are doing completely different things. SQLModel is just causing you more work later that could have been avoided by just copy/pasting the SQLAlchemy models to Pydantic in the first place.
But even then you'll get people implementing business logic in Pydantic validators. I feel like basic layered architecture is being forgotten.
Hello, OP there, I have many use cases that fall outside of FastAPI or web apps in general, and this pattern allows me to consolidate that logic in a re-usable way.
We also have SQLSpec[1] (Work in progress) that could maybe a better use case for you with raw SQL
1. https://github.com/litestar-org/sqlspec
FastAPI and it's very opinionated "ecosystem" of "easy to use" and "hipster-esque documented" tools are fast-becoming a horrible one-man show version of Django, and we will all regret going so deep into it using it, one day. Until then, sure we can use it and it mostly makes sense and it mostly works really very well. Hopefully the community matures and moves away from opinionated tooling that forces you into the "one true way".