Flow query refactor

Better flow query refactor without HSTORE

replaces https://github.com/Tahi-project/tahi/pull/717
Good call. Yeah that looks better.