In a django project, if a situation comes that Django ORM is not able to execute some complex queries then there are 2 options:
-
Use Raw Sql queries
-
Use SqlAlchemy
I want to know if there are some rules like some pros and cons of both which can guide me to choose one of the above 2 options.
Or is it entirely depends on what we like?
Best Answer
ORM
Raw SQL
The issue of complexity
I'm sure I'll get dinged for this, BUT.
Unlike many of the its proponents I do NOT think ORMs free the developers from understanding SQL. You still have to understand SQL because you will end up dealing with the SQL your ORM creates. And here is why:
This doesn't mean you shouldn't use an ORM. They can still reduce the amount of code you have to write. But you should understand you may not get all the benefits you think you will.