Bugfix: Missing a return statement.
Using handlebars templates to tidy the SQL mess.
Added SQL templates for postgres.