           (is (= [{:certname certname
                    :facts {"x" "24", "y" "25", "z" "26"}}]
                  (query-factsets :certname :facts)))
-          #_(is (= (query-to-vec
-                  "SELECT fp.path as name,
-                          COALESCE(fv.value_string,
-                                   cast(fv.value_integer as text),
-                                   cast(fv.value_boolean as text),
-                                   cast(fv.value_float as text),
-                                   '') as value,
-                          fs.certname
-                   FROM factsets fs
-                     INNER JOIN facts as f on fs.id = f.factset_id
-                     INNER JOIN fact_values as fv on f.fact_value_id = fv.id
-                     INNER JOIN fact_paths as fp on f.fact_path_id = fp.id
-                   WHERE fp.depth = 0
-                   ORDER BY name ASC")
+          (is (= (query-facts :certname :name :value)
                  [{:certname certname :name "x" :value "24"}
                   {:certname certname :name "y" :value "25"}
                   {:certname certname :name "z" :value "26"}]))

  [:v4])

(defn query-factsets [& cols]
  (->> (query-to-vec "select certname, (stable||volatile) as facts, environment, producer_timestamp from factsets")
       (map #(update % :facts (comp json/parse-string str)))
       (map #(select-keys % cols))))

(let [certname  "foo.example.com"
      facts     {:certname certname


      (is (= [{:certname certname
               :facts {"a" "1", "b" "2", "c" "3"}}]
             (query-factsets :certname :facts)))
      (is (= (query-facts :certname :name :value :environment)
             [{:certname certname :name "a" :value "1" :environment "DEV"}
              {:certname certname :name "b" :value "2" :environment "DEV"}
              {:certname certname :name "c" :value "3" :environment "DEV"}]))
