3 ms·
One case I find really annoying to write in SQL is inserting or updating entities with several many-to-many relationships. That is just plain annoying to do by
by fabian2k 6y ago
One case I find really annoying to write in SQL is inserting or updating entities with several many-to-many relationships. That is just plain annoying to do by hand, so I'd either have to use an ORM or write a small wrapper myself for this.
Reading entities with many-to-many relationships is also often easier with an ORM, though you really have to be aware how the ORM will write this kind of query to avoid issues. ORMs are a very leaky abstraction when performance is concerned.
Another part that is very useful is the query building itself, though you can get that without an ORM. Having composable query fragments is very useful, doing that by hand is extremely tedious, error-prone and a potential security risk if you're not careful.
I'm comfortable writing SQL by hand, but I do prefer to have an ORM as long as I can also bypass it for queries that are difficult or impossible to do with the ORM. But an ORM can't replace knowing how databases work, and they do require you to understand more under-the-hood details than most other types of libraries.
- cbetti 6y agoPersonally, I think ORM has a reasonable use case here, but I also find doing this using SQL to be straightforward and easier to reason about during future refactors. Take a look at JDBI's Repository pattern for a simple compromise between SQL and ORM for this use case in particular.