 (def v3-query->sql
   (partial query->sql resource-operators-v3))
 
-(defn- aggregate-resource-parameters
-  "TODO docs & conditions"
+(defn- consolidate-resource-params
+  "Given the raw query results from the database, consolidate all the resource
+  parameters for each resource and put them into a hash on each resource keyed
+  at `:parameters`."
   [query-results]
   (let [metadata_cols [:certname :resource :type :title :tags :exported :file :line]
         metadata      (apply juxt metadata_cols)

                             [(:name param) (json/parse-string (:value param))])))))))

(defn- build-comp-fn
  "TODO docs & conditions"
  [{:keys [field order]}]
  {:pre  [(keyword? field)
          (or (= order "ASC")
              (= order "DESC")
              (nil? order))]}
  (fn [x y]
    (if (or (= order "ASC") (nil? order))
      (compare (x field) (y field))
      (compare (y field) (x field)))))

(defn- combine-comp-fns
  "TODO docs & conditions"
  [comp-fn1 comp-fn2]
  (fn [x y]
    (let [val1 (comp-fn1 x y)]
      (if (= val1 0)

    (vec sorted)))

(defn- post-process-results
  "Given the results of the query and the optional order-by paging clauses,
  consolidate the results into a form appropriate for returning to the user
  and sort them based on the order-by clauses, if there are any."
  [query-results {:keys [order-by]}]
  {:pre  [(vector? query-results)
          ((some-fn nil? vector?) order-by)
          (every? map? order-by)]
   :post [(vector? %)]}
  (let [consolidated-results (consolidate-resource-params query-results)]
    (if (empty? order-by)
      consolidated-results
      (sort-on-order-by consolidated-results order-by))))

(defn limited-query-resources
  "Take a limit, a map of paging options, and a map of SQL queries as
