I'm a fan of using raw sql like this but curious if anyone has solved deduplicating common statements and dynamic queries in a good way.
For example:
1) Imagine lots of queries having to show the results in the context of a user and therefore use the same JOIN and WHERE clause all over. Not being DRY, this breaks down when having to change the clause at all.
2) Imagine a reporting page that allows for filtering and ordering by different columns and therefore need some way to compose the final sql.