Factor out to-sql to its own file
Add support for modifiers like ALL and DISTINCT