3 ms·
I get that, and I'm comfortable writing raw SQL but as the system grows larger and requirements change I inevitably run into the fact that raw SQL doesn't compo
by andreareina 6y ago
I get that, and I'm comfortable writing raw SQL but as the system grows larger and requirements change I inevitably run into the fact that raw SQL doesn't compose. For me the query builders hit that sweet spot of mapping almost one-to-one to raw SQL, while giving me composition when I need it.
- platz 6y ago99% of the time you should'be be composing SQL. If you need composition at the DB level, that is what Views are for.
- treis 6y agoI'm not sure why you think we shouldn't be composing SQL. What about for cases like: User.banned.posts.flagged where we want all flagged posts from banned users. Posts.flagged.today where we want all flagged posts from today User.created_today.posts.flagged where we want all flagged posts from users created today
- platz 6y agoOr you could just create a View for flagged posts and join on that as appropriate, no ORM needed. There's probably some room for limited compositional SQL, but there are ways to get that without a full ORM, given your type system is expressive enough.