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
1
u/jshine13371 Jul 06 '26 edited Jul 06 '26
Not at all. I'm replying to your comment because that is the example you provided. I'm not going to reply to you about something you didn't say lol. And I actually believe there are uses for ORMs, I've used them in the past myself. So I'm not arguing that they shouldn't exist either.
No it didn't. It was discussing the opposite actually. Pagination is stupid, in my opinion. 200k rows is not a lot of data, and if that's what your end users normally work with, then bring all the rows down to the client side and subsequent operations are easier and faster.
Sure, give a concrete example for me to conceptualize and I'll provide the equivalent solution on the database side.
There's a pretty common level of implementation and features of an ORM that we can talk sensibly about them, instead of arguing about semantics and definitions.
Yea but it makes this sentence irrelevant since I'm not here to argue semantics, as I just stated. You understood the point of my previous reply on this well enough.
"Rightful" is subjective. But good luck with that approach when you need to repeat the same business logic in other consumers such as the reporting and BI layers because they can't always consume your app code. I prefer not having to maintain my business logic in 5 different places. The database layer makes DRY for business logic super easy. Also, since business logic very commonly defines the shape of the data, handling those transformations in the database layer is typically the most performant place to do them, besides having the best data integrity, since then you're leveraging an engine designed for data manipulation.