Extract some functions from to-sql

Extracted where-clause, limit-clause, and offset-clause as
functions and renamed a few things.
Refactor to-sql to take optional semi? argument
Test to-sql for selects in more top-down style

Factored out functions for each of the clauses. Added a top-down
test for to-sql showing that it processes all of the clauses and
assembles them in the correct order.