See Esqueleto in Haskell, Slick and Quill in Scala, probably LINQ or some variant on .NET in C#/F#.
All support building up arbitrarily complex queries based on statically typed query fragments.
String fragment "composition" is like banging rocks together.