         val1))))
 
 (defn- sort-on-order-by
-  "TODO docs & conditions"
+  "Sort the results of the query based on the order by clauses."
   [query-results order-bys]
+  {:pre  [(vector? query-results)
+          (vector? order-bys)
+          (every? map? order-bys)]
+   :post [(vector? %)
+          (= (count %)
+             (count query-results))]}
   (let [order-bys  (mapv #(update-in % [:field] keyword) order-bys)
         comp-fns   (map build-comp-fn order-bys)
         final-comp (reduce combine-comp-fns comp-fns)

    (vec sorted)))

(defn- post-process-results
  "TODO docs & conditions"
  [query-results {:keys [order-by]}]
  (let [aggregated-results (aggregate-resource-parameters query-results)]
    (if (empty? order-by)
      aggregated-results
      (sort-on-order-by aggregated-results order-by))))

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

(def v3-query->sql
  (partial query->sql resource-operators-v3))

(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)
