3 ms·
That's pretty much exactly how I feel. I gave a talk a few years ago about doing advanced SQL things in ActiveRecord [0]. The talk suffered I think from lacking
by pjungwir 7y ago
That's pretty much exactly how I feel. I gave a talk a few years ago about doing advanced SQL things in ActiveRecord [0]. The talk suffered I think from lacking a unifying idea and because I tried to offer something to the whole spectrum of experience (from "this is a join" to "this is how you can express a CTE/lateral join/window function in AR"), but the real unifying motivation/message was that with AR you can have your cake and eat it too.
I've approached tons of problems by making it work in SQL first and then translating it into AR afterwards (to some degree or other). I would reject an ORM without an "escape hatch", but AR is wonderful for taking away the boilerplate while still letting you write SQL when you need it, and even letting you make SQL more composable by defining scopes.
I'm just wrapping up a couple C# projects where everything is direct SQL, and oh man is it verbose and painstaking! Every day I long for more Rails work. :-)
[0] https://github.com/pjungwir/rails-and-sql-talk https://github.com/pjungwir/rails-and-sql-talk
- icheishvili 7y agoAR is the gold standard. AR + extended gem + Arel covers almost 100% of the problem space. For everything else, use views or set returning functions and wrap them up in AR.
- mst 7y agoAR took at least ten years to catch up with the perl state of the art but does seem to be doing pretty well these days.
- shade 7y agoAs a note - I've done a lot of SQL in C#, and Stack Overflow's Dapper[0] library is _fantastic_ for dealing with that. You can pass in all the SQL you like, or a stored procedure, and it deals with virtually all of the query parameterization and boilerplate around getting results out of the DB. It's saved me hours of tedium and typing. It's the perfect micro-ORM. Eliminates boilerplate, gets out of the way otherwise. [0] https://github.com/StackExchange/Dapper https://github.com/StackExchange/Dapper
- nycdotnet 7y agousing Dapper at least?