(maint) Add pretty SQL formatting

This patch converts all SQL code from the query engine into a pretty format
so it is easier to read from the debug output.

Signed-off-by: Ken Barber <ken@bob.sh>
I think that if we're going to make a function like this, it should be a predicate (maybe `class-exists?`), and we should memoize lookups so we don't repeatedly pay the price for it.