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
2
u/jshine13371 Jul 06 '26
Your search page is now a full CRUD-like app itself based on functionality and use case.
They can. Not following why they wouldn't so far. In fact, you should only have to query the database once per search based on the use cases you've described so far. After retrieving the data, the remaining operations should happen locally, until the bulk update changes are actually saved back down to the database (which has no need for "the same WHERE" clause).
Sure you can, but it's not clear how you mean. In a parameterized query, the same
WHEREclause can be used by an advanced search page over and over again, without repeating yourself in code. But again, I'm sure you're meaning something else, it's just unclear what that something else is?Not at all, as demonstrated in what I just said above. And ORMs are far more complex than that, that you'd still be a long ways off.
It's an equally important (some could argue more important) part of the system like any other part. Almost no modern applications can function without data. Data is a core piece of society.
I personally love refactoring my implementation of the business logic into the database layer to fulfill the DRY principal, among other benefits.
This is a random statement and has nothing to do with OP's question on ORMs.