Extract the creation of TsdbQuery objects into a QueryBuilder

It's still needed but it's been moved to `QueryBuilder`.