Using ORMs vs Writing Raw Queries
This is not exactly a stand off between the two concepts, rather an opinion piece based on my experiences on where ORMs shine, and where raw queries have their unwavering place. This article will use SQL for examples, but the points may apply to any database that you're using.
Here's my opinion: it's best if you use a combination of both. When you're building basic CRUD APIs and such, ORMs are fantastic. When your application becomes complex with more complex queries, and your data volume grows, then it becomes imperative that you use raw queries for a number of reasons.
So let's get into it!
Your team is building a production-grade application connected to a database, and you want the application to be scalable, maintainable, and fault tolerant. How you choose to interact with your database can have a significant impact on your development as well as your live product / service.
Pros of ORMs
ORMs are awesome in their own way, where some concepts have been built and improved over decades. First let's look at some of the key benefits of using ORMs:
领英推荐
Cons of ORMs:
One general con of using any abstraction layer is that you lose sight of the inner workings of the technology. For example, for most applications you will probably get by with most of your business logic using ORMs even if you don't learn any SQL. This is very bad.
It might seem like a good thing because you can get an application up and running without knowing all that much, but in the long run you as an engineer will suffer if you don't equip yourself with the skills and knowledge of SQL features and writing optimized queries. This will not only help you grow as an engineer but will help you build resilient and performant applications.
So if you're learning about ORMs for the first time, they might seem amazing! However, it does not come without trade offs. Hope this article helps give some insight into what you might deal with when building real world applications.
Software Engineer | Laravel | PHP | jQuery | WordPress | Database | Git |
1 年it depends
Django | REST API | ML | Web Development | Python | JavaScript
1 年As a beginner, I believe that working with ORM can be overwhelming without a basic understanding of minimum SQL queries. By the way, I gained some important insights from this article.
Freelance Consultant at Freelancer
1 年ORMs are always useful and we get a chance to use multiple database according to the company requirements. At the same time it is a overhead as well when there is no need of using multiple database. Hence combined usage will be better.
Software Engineer | Competitive-Programmer
1 年Shawon Majid, that's what we were talking about ??