TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Migrating to SQLAlchemy 2.0

198 点作者 brainless大约 4 年前

15 条评论

parhamn大约 4 年前
I’ve seen quite a few shops which effectively hit every python db&#x2F;networking&#x2F;pooling foot gun you could possibly encounter while using SQLAlchemy.<p>People cargo cult the flask intro tutorial and have no clue how session binding works, where the transactions are, how committing works, etc because it’s all tucked away in magical middleware and singletons. As the code base grows so does the mess of blocking txns, accidental cross joins, pool exhaustion, and so on.<p>It’s a great tool from a technical expressiveness perspective but terribly full of operational foot guns. Beware and use Django until you’re sure you AND your team know what you’re doing.
评论 #26184692 未加载
评论 #26185178 未加载
评论 #26184057 未加载
评论 #26185099 未加载
评论 #26201305 未加载
评论 #26186259 未加载
评论 #26190835 未加载
评论 #26186385 未加载
avolcano大约 4 年前
One of the most interesting 1.4&#x2F;2.0 changes is first-class asyncio support, not just for core (the query builder) but for the ORM layer as well: <a href="https:&#x2F;&#x2F;docs.sqlalchemy.org&#x2F;en&#x2F;14&#x2F;changelog&#x2F;migration_14.html#change-3414" rel="nofollow">https:&#x2F;&#x2F;docs.sqlalchemy.org&#x2F;en&#x2F;14&#x2F;changelog&#x2F;migration_14.htm...</a><p>As this notes, there&#x27;s several changes you have to make to your assumptions around the ORM interface. SQLAlchemy, for better or worse, supports &quot;lazy loading&quot; of relationships on attribute access - that is, simply accessing `user.friends` would trigger a query to select a user&#x27;s friends. This kind of magic is at odds with async&#x2F;await execution models, where you would instead need to run something like `await user.get_friends()` for non-blocking i&#x2F;o.<p>It looks like they&#x27;ve done some good work in making the ORM layer work reasonably well with these limitations (<a href="https:&#x2F;&#x2F;docs.sqlalchemy.org&#x2F;en&#x2F;14&#x2F;orm&#x2F;extensions&#x2F;asyncio.html#preventing-implicit-io-when-using-asyncsession" rel="nofollow">https:&#x2F;&#x2F;docs.sqlalchemy.org&#x2F;en&#x2F;14&#x2F;orm&#x2F;extensions&#x2F;asyncio.htm...</a>), but I wonder if removing &quot;helpful magic&quot; like this will push more people to stick with the query-builder, rather than the ORM.
评论 #26184503 未加载
qatanah大约 4 年前
Thanks for the hardwork zzzeek! I&#x27;ve been using sqlalchemy for 5+yrs now and it&#x27;s great to work with!<p>I like SQL and I like the ORM. When things go tough like doing complicated JOINs or OLAP. I just go raw sql. If it&#x27;s OLTP, updates and simple lookups, ORM makes the code readable.<p>The alembic migration is also great! I can craft the models to design with postgres features (index, multi key index, pk uuid) and etc..<p>I&#x27;d would love sqlalchemy to invest more on scaling. Although scaling is an entire book of discussion. Not much resources are there for handling multiple db, sharding (maybe too much to ask).<p>My opinion is, love SQL and Love the ORM. You&#x27;ll need both to appreciate it&#x27;s power. It&#x27;s like learning VIM, a long term investment tool and hard to :wq
grouseway大约 4 年前
Lots of major changes, so I hope it doesn&#x27;t create a schism.<p>Do SQLAlchemy users appreciate how lucky they are? I generally prefer to use c#&#x2F;.net but the 3 Microsoft ORMs (linq-to-sql, ef, ef.core) are all half baked. I don&#x27;t know much about ActiveRecord, Django or other ORMs.<p>I wish I could have this sort of feature set and dynamic abilities that I get in sqlalchemy on the .net side. I say that as someone who loves SQL but appreciates the conveniences of a powerful ORM.
评论 #26185087 未加载
评论 #26186125 未加载
radus大约 4 年前
The description of the new direction for 2.0 sounds great, but as someone who isn&#x27;t using SQLAlchemy currently (I prefer peewee) I&#x27;d be curious to see what it looks like without the assumption that I&#x27;m migrating from a previous version. I guess that&#x27;s not yet fully settled?
评论 #26184872 未加载
评论 #26183858 未加载
评论 #26184725 未加载
closed大约 4 年前
I&#x27;ve been building data analysis tools on top of SQLAlchemy&#x27;s declarative system over the past couple years. It&#x27;s got to be the most well documented, carefully designed library I&#x27;ve ever interacted it :).<p>It looks like most of the changes in 2.0 are aimed at the ORM system, which makes sense. I think a lot of complaints that come up have more to do with the complexity of interacting with a SQL database, so appreciate the effort in the docs not just laying out an API, but essentially educating around the problem domain.
gigatexal大约 4 年前
I got my start in IT as a DBA. SQL and good table design come naturally. So when it came time to join a company as a developer I sprang for raw SQL only to find this SQLalchemy ORM. I couldn’t wrap my head around it at first. All the ceremony to get to what I wanted to do just got in the way. I felt trapped. But it’s ubiquitous and I have to adapt. So I’m learning. And there’s a whole lot of benefit being able to define a model and have it render on any database. Paired with Alembic migrations can be pretty simple.<p>I miss having 100% control over the queries, knowing exactly how they looked and analyzing each before committing them to main. But nobody has the time to hand craft artisanal queries and leverage every intricate detail of a database when they’re trying to move ever faster and ship features.
评论 #26187767 未加载
throwdbaaway大约 4 年前
Good to see the removal of autocommit, with the detailed discussion of the design decision. I&#x27;ve always felt a little uneasy when going with autocommit=False in my old projects, thinking that the default of autocommit=True was the &quot;blessed&quot; way to use SQLAlchemy.<p>EDIT: Looks like autocommit=True has never been the default, must have been some possibly 3rd party documentation.
luord大约 4 年前
I&#x27;m particularly interested in the support for dataclasses. It&#x27;s going to make modeling the application while decoupling from the data layer itself easier, I think.
评论 #26188333 未加载
temuze大约 4 年前
zzzeek is an absolute beast and the SQLAlchemy codebase is a gem to read.
liquidify大约 4 年前
I used their ORM library in a medium sized project. As the project grew, it turned a nightmare scenario. After that experience, I stick to core and raw SQL queries. I hope 2.0 brings some meaningful changes.
评论 #26184795 未加载
stilisstuk大约 4 年前
Why is nobody ever writing raw SQL? I&#x27;ve never understood why ORMs are sine qua min.
评论 #26185471 未加载
评论 #26185472 未加载
评论 #26186839 未加载
评论 #26185475 未加载
评论 #26185493 未加载
评论 #26185538 未加载
评论 #26186568 未加载
评论 #26185748 未加载
评论 #26191658 未加载
psychometry大约 4 年前
I kind of wish some of the SQLAlchemy core devs spent a bit of time using ActiveRecord to appreciate how an ORM can make defining and querying relations straightforward and easy.<p>Right now, using SQLAlchemy creates a &quot;now you have two problems&quot; kind of workflow: first you figure out the SQL need, then you spend at least that long figuring out how to write it with the ORM. I never felt this way about ActiveRecord.
评论 #26184651 未加载
评论 #26185293 未加载
评论 #26185342 未加载
评论 #26186752 未加载
The_rationalist大约 4 年前
How does it compare to the JPA and active records?
qbasic_forever大约 4 年前
Modeling their migration off the Python 2 -&gt; 3 migration. Bold move, let&#x27;s see how that works out for them.