For factoring out common query parts have a look at the composing applications guide: http://diesel.rs/guides/composing-applications/
The tools you usually want to use there are the auto_type macro, BoxableExpression (for dynamic fragments, but also as trait bound) an the HasQuery macro to share common base queries.
There are a few more details in this (https://blog.weiznich.de/rustweek_2025.html#/title-slide) set of slices from last years RustWeek workshop


At least
#[auto_type]and usingBoxableExpressionas trait bound doesn’t need any boxing at all.That written, as others already pointed out: Boxing and dyn dispatch are sometimes the right solution. You also should keep in mind that in most cases the performance penalty of the allocation or the indirect function call is not significant compared to say a network roundtrip or an io operation. The only situation with Diesel queries where I found that allocations matter are for hot loops of trivial queries on an in memory SQLite database connection. There it costs you around 50% of performance. Otherwise you won’t notice much difference.