Submitted by musou in programming
seems like almost every popular language has at least one library for making SQL queries in a domain-specific language that maps language functions onto SQL syntax. and that's really cool for every day type queries (getting rows matching a list of IDs, inserts, updates, deletes, getting associated records through relations).
sooner or later, however, i end up needing to write a query that's really complicated and then i always feel like i'm tripping over my own shoelaces. and the usual way out is to write the query in SQL first, then try to translate it back into library-speak after.
this happened today. i had to calculate a bunch of stuff from very normalized data, and ended up writing three subqueries with a bunch of left joins inside each one, all stapled together by more joins. and now i have to figure out how to write it in Ecto's DSL.
and since i wouldn't have to do that if i didn't choose to use Ecto in the first place, it always feels bad because i know it's all extra work i have made for myself. maybe it still saves me effort overall, but it feels kind of hard to tell sometimes.
what do y'all think about ORMs, and query DSLs? got any you like to use? any horror stories?
lainproliant wrote
I feel that ORMs can be useful in certain projects, especially ones where you are building a small app to interact with an existing database and want to get off the ground running fast. If you end up interacting with a dataset that is very relational, you'll start running into some of the edge cases of optimization in ORMs and end up with N+1 queries and such.
I have experience with Hibernate in Java and SQLAlchemy in Python. In general I like them both but I tend to avoid them for projects where the DB schema is simple and just roll my own DAO layer.