Re:What ORMs Have Taught Me: Just Learn SQL (2014)
by metafunctor on Wednesday October 21, 2020 @05:10AM
(#24846059)
The Django ORM is pretty good, and I like it. But, to squeeze out performance, wouldn't you say you have to actually understand what is going on in the database?
[ Parent
| on HN ]
Re:What ORMs Have Taught Me: Just Learn SQL (2014)
by BozeWolf on Wednesday October 21, 2020 @08:28AM
(#24847095)
Agree! I like django's ORM and I love SQL databases. It is nice that your in-code model changes, will reflect the schema changes in the database. And migrations are a blessing. (Of course it has some foot guns.)
For optimizations: my_queryset.explain(verbose=True, analyze=True) is very nice to understand what is going on. If you cannot get it done with django's database abstractions, there is always:
my_queryset.extra() or even my_model.objects.raw(). Where the last one maps the result to the model, for free.
To others responding that ORMs are bad: IMHO saying that raw sql is better than ORMs is short sighted. Many simple things are nice in ORMs. Queries are often simple. Today, in django, complex queries are also nice. For edge cases raw sql can be better.
Extending queries is also super easy with a good ORM, where with raw sql you would have to maintain two almost the same queries.
Just remember to run and inspect queryset.explain().
Re:What ORMs Have Taught Me: Just Learn SQL (2014)
by darkhorse13 on Wednesday October 21, 2020 @03:29PM
(#24851168)
Fully agree with this. These discussions are always this or the other, but you can easily have both in the same project. Django's ORM and raw SQL functions prove that.
Re:What ORMs Have Taught Me: Just Learn SQL (2014)
by sjwright on Wednesday October 21, 2020 @05:59AM
(#24846263)
And more importantly, you'd want to design your database to be optimal for complex SQL queries and not whatever generic structure that matches your programming objects.
Re:What ORMs Have Taught Me: Just Learn SQL (2014)
by darkhorse13 on Wednesday October 21, 2020 @03:25PM
(#24851129)
I don't see why those things have to be mutually exclusive. You can understand your database and still use an ORM.
Re:What ORMs Have Taught Me: Just Learn SQL (2014)
by metafunctor on Thursday October 22, 2020 @03:37AM
(#24855736)
Yep. My point is that if you use an ORM, but don't understand your database, you're asking for trouble.