|
I'm sick of the argument that those who advocate for the use of an ORM have a dislike of SQL, or simply don't understand it. Perhaps this is true of newer developers who have "grown up" on ORMs, but for the most part advocating for an ORM is simply wanting to employ the "don't repeat yourself" thing and having enough battle scars to know that trying to compose your own SQL statements results in vulnerabilities, bugs, and a mess. > If you define your database properly typed, defaulted, and not null unless an update field that sort of layer isn't needed at all. Which is a laudable goal but not realistic if you've worked on any backend that has even a hint of organic growth or legacy. I know of at least two books on the subject of dealing with anti patterns in and the refactoring of database schemas. Database schemas are the mortgage of technical debt, they can take literally decades to pay off if you don't get them "right" in the first place, or you pivot, or you're growing quickly, or you have a large team. Using an ORM allows you to abstract away and isolate a lot of the technical debt, create single entry points, and then fix those. And in the part where using the ORM's syntax would obfuscate or complicate compared to SQL, then just write your own SQL query anyway and put this in a virtual view. Sure, you can create your own entry points that handle the madness and domain knowledge, with your own SQL handling to put the pieces together that return a nicely mapped object or data structure. Then what have you done? You've written your own ORM. |
Bugs? You're shitting me, from what? Untested queries?
A mess? Clean it up. You can make a mess with an ORM too.
> Which is a laudable goal but not realistic if you've worked on any backend that has even a hint of organic growth or legacy.
Except it is realistic and I have cleaned up a lot of "organic growth" and "legacy code" like this.
> I know of at least two books on the subject of dealing with anti patterns in and the refactoring of database schemas.
Yea.. where do you think I got these ideas?
> Database schemas are the mortgage of technical debt, they can take literally decades to pay off if you don't get them "right" in the first place, or you pivot, or you're growing quickly, or you have a large team.
Database design is not hard and your schemas/changes should be peer reviewed like any code. It's also not static, yes, some, SOME, very few situations are essentially unchangeable.
But most database design is easily extended without causing breaking change.
Breaking change is more problematic but not in any way more or less than any other breaking change.
Then again, I'm kind of curious how any of these problems are solved by an ORM.