What's New in SQLAlchemy 2.1?
docs.sqlalchemy.org
docs.sqlalchemy.org
Just write SQL. I figured this out when I realized that my application was written in Rust, but really it was a Postgres application. I use PG-specific features extensively. My data, and database, are the core of everything that my application does, or will ever do. Why am I caring about some convenient abstractions to make it easier to work with in Rust, or Python, or whatever?
Nah. Just write the good SQL for your database.
As with most things, it is a balance.
For the CRUD side it's worth it I think, but yeah definitely a balancing act between the two.
Yet again, balance.
> And they're always lazy, so you never really know when the N+1s are going to happen.
There are tools to detect this. Please use them regardless. Even if you're writing queries but hand, enough functions on the stack can hide an N+1
> > And they're always lazy, so you never really know when the N+1s are going to happen.
> There are tools to detect this. Please use them regardless. Even if you're writing queries but hand, enough functions on the stack can hide an N+1
I don't want to have to use a tool to "detect" anything. I want my queries to return exactly what they're expected to return, or my code will fail. No surprises.
a) It is tricky to make raw SQL composable in a safe way, and
b) I still need to map all those rows into objects somewhere, but now i have to do it by hand
Start with whatever you want, write raw SQL or use an ORM, your choice.
If you find yourself doing a bunch of string formatting and concatenation, then use more ORM features. The more loops, if-statements, and regexes[0] involved in your "raw SQL", the more important it is that you start using a proper ORM.
If you find yourself struggling to get the ORM to do exactly what you want, and you're repeatedly reviewing the SQL it generates, then use less ORM and more hand written SQL. Check to see if your ORM allows writing only a portion of the SQL by hand (SQLAlchemy does).
SQL seems far more portable.
It is no small feat to create compatibility for modern Python features like type hints and async in a library that has its roots in Python 2, it has absolutely exceeded expectations in that regard.
(There's also Atlas for Python but it isn't much better, a lot of fiddly config files https://atlasgo.io/guides/orms/sqlalchemy)
One other reason for its popularity and success is how engaged the orginal developer is with the overall community.
I can't disagree more. Identity map based ORMs are _awful_ to use, in almost every way.
Since Entity Framework Core matured enough and I've discovered LINQ, I said my goodbyes and switched to C#.
Thanks, Mike Bayer and all maintainers, for helping me earn my living using your software all those years.
this is really premature to be posting on hacker news, we're hoping for 2.1 being ready sometime middle of next year if we are lucky