Why do people use sqlalchemy CORE to save data and use sqlalchemy ORM to query data

I found that some people use the sqlalchemy ORM to query the data, but use the sqlalchemy CORE to insert the data. Why would they do that? why don't they support it in the same Python code (class)?

Sqlalchemy ORM will migrate to CORE finally right? Using the kernel and orm at the same time, what makes the program faster? I found a suggestion here ( What is the difference between sqlalchemy core and ORM? )

in particular based on information only available at runtime

does this mean CORE is faster or what? I am really confused. anyone can help, thanks in advance.

+3


source to share


1 answer


You should take a look at the performance comparison and explanation in the docs. This mainly explains how and why ORMs are not suitable for large bulk inserts, which Core can handle just fine. There are bulk operations in a session , but they have their tradeoffs.



While the ORM is indeed built on top of Core, it does a lot more than just "store these objects in the database". It monitors changes to objects in the session and periodically flushes those pending changes to the database. It is part of a unit of work . Anything that stores books comes with a price, but instead you don't have to worry about the order of operations when storing a complex object graph in a relational database. Sometimes you don't need all this and just need to insert a few lines into the base.

+6


source







All Articles