4 ms·
I wouldn't call these shortcomings of Django's ORM as much as design decisions that may or may not be agreed with. I've found Django's ORM pretty useful in that
by ashray 14y ago
I wouldn't call these shortcomings of Django's ORM as much as design decisions that may or may not be agreed with. I've found Django's ORM pretty useful in that, it reduces the amount of typing you need to do. BlogPost.objects.filter() is shorter than "SELECT * from BlogPost where ....". Of-course, Django's ORM gives you a few ways to implement complex SQL statements. However, ORMs in my opinion aren't that great with dealing with complexity. They can take you only so far before you realize that "Hey, I could write this query much better manually". At the point where you need that, ORMs are pretty useless. There've been times that I've manually enforced database level constraints and enforced uniqueness on 2 or more columns with a replace statement to avoid race conditions. An ORM wouldn't be able to handle that kind of thing. Not at the moment anyway.
But that brings me to my point. Do we need to keep running after abstraction (ORMs) when the needs become sufficiently complex and the abstraction ends up making things more opaque ?
ORMs are great for simple stuff. Raw SQL rules for complex stuff. Yes/No ?
- pplante 14y agoI agree with you about the use of raw SQL when a query gets too complex. Often I find that the ORM is capable of expressing a query I have in mind, but it might do it inefficiently. Sometimes I will rewrite this using SQL. Usually what limits me is how much post processing I will have to do on the results to attain my desired goal. Often I avoid putting any work on my db beyond filtering and grouping of results. Its typically much easier to scale out app/web servers than it is to scale out databases to support a heavy query workload.