by Beltiras · 10y ago · 0 comments
EDIT: I'm not saying this is a waste of time from a developer who obviously puts out quality projects. I'm saying I don't see myself using it. I'm most familiar and comfortable with the Django ORM and have overseen a large project with it. There were several raw queries when I took over but once I left it there were none and all the replacement I did was clean ORM queries more performant than their raw SQL predecessors.
RDBMS <-> Objects are a poor match. So much so, many pursued NoSQL to find relief from the pain.
I am pretty familiar with the Django ORM where you hit limitations fairly early (if you are writing any moderately complex queries). But I still use it for maybe 90% of the stuff I do because that 90% involves pretty simple queries, and it saves a ton of typing, and integrates well with the rest of the Django ecosystem.
Updating data is a good example. I recently split up some database strings into multiple columns. At first I just wrote the SQL to update a joined table. Then I needed to get regexes involved to pull out certain parts of the string. Doing that in SQL gets ugly, and its far simpler just to use the ORM to pull out the data required and operate on it in Python on a loop.
I don't see the ORM as an either / or, but as a complimentary tool to SQL.
It does have the overhead of having to learn the ORM, but once you do that, it pays off.
That's the catch right there.
AppComment.objects.annotate(content_len=Length('content')).all().aggregate(Sum('content_len'))
https://docs.djangoproject.com/en/1.9/ref/models/expressions...