r/SQL • u/yughiro_destroyer • Jul 06 '26
Discussion Why do we need abstractions over SQL?
When I mean abstractions, I mainly mean OOP and ORMs.
SQL is so simple and beautiful. Tables with rows and columns are easy to understand. And once you pick up the SQL syntax, you can pretty much achieve anything with queries. Not to mention that SQL is universal and works everywhere and anytime.
Then you have the software development world... where you're asked to constantly use ORMs or map records as OOP objects. Why? ORMs are limited and do not have the flexibility of simple queries. Also mapping records as objects increases bloat, reduces performance that can hurt if the application grows and is overall not as straightforward to work with.
The only good things that ORMs are doing by default are to provide data safety and prevent SQL injection. But with some minimum and basic knowledge and discipline, you can write pure queries without having those problems. Any ideas?
View all comments
Show parent comment
0
u/Lumethys Jul 06 '26
You are talking like my example is the only use case of an ORM ever.
Even in that advanced search example, you counter argument just assume a paginated query. A lot of the system i deal with, a user can search about 200k record, export all those 200k record, and update those 200k record. The WHERE clause is the same, but the actions are different.
And even then, there are countless other example, builder pattern where some query inherits part of other query, for example, is also a popular use case.
Is there a RFC that define what is an ORM? Just like a "framework" can be just a 10 line router by file name. An ORM can just be as simple as a 1 line "mapping" from a result set to an "object"
Just because it isnt very useful, or people wouldnt use it, doesnt make it not an ORM
Funnily enough, i spend a lot of my professional time removing stored proc and triggers, and move them under the rightful ownership of application code