Why Is That People Use Sqlalchemy Core To Save Data And Use Sqlalchemy Orm To Query Data
Solution 1:
You should have a look at this performance comparison and explanation in the docs. Basically it explains how and why the ORM is not suited for large bulk inserts that the Core might handle just fine. There are bulk operations available in the Session as well, but they have their trade-offs.
While the ORM is indeed built on top of the Core, it does a lot more than just simple "save these objects to a database". It tracks changes to objects in the session and flushes those pending changes to the DB periodically. This is part of the unit of work pattern. All that book keeping comes with a price, but in return you don't have to worry as much about the order of operations when persisting a complex object graph in to a relational database. Sometimes you don't need all that and want just to insert a bunch of rows in to a database.
Post a Comment for "Why Is That People Use Sqlalchemy Core To Save Data And Use Sqlalchemy Orm To Query Data"