More flexible construction of querries
Currently "normalization" and construction of the typed query AST is intertwined and the user is constrained from writing queries that are not in a "normal" form by ad hoc type constraints.
A better idea is to lift the whole AST to the type level and then have a type family that checks if the AST is compilable to SQL.
Notes:
- If we want to compile to a single query there is only a single possible ordering of various transformations that we can have in the end. (filtering before sorting, sorting before limiting etc.)
- Figure out which transformations can commute and transform the AST by floating every transformation to the appropriate layer for compilation
- Consider whether it only makes sense to check the final AST or if the checks can be recursive and incremental
- Consider implementing more flexible compilation that can compile any kind of AST with a warning if it requires nested queries