Use multiple connections when querying the query view.

This reduces the query time.
Don't duplicate class/method definitions when building up the source
of the view query function.