massive rewrite to support more abstract query definitions off the command line, beyond just feeding a dumb select fragment