 (defn persist-classes!
   "Given a certname and a list of classes, persist them in the db"
   [certname classes]
+  {:pre [certname
+         (coll? classes)]}
   (let [default-row {:certname certname}
         classes     (map #(assoc default-row :name %) classes)]
     (apply sql/insert-records :classes classes)))

(defn persist-tags!
  "Given a certname and a list of tags, persist them in the db"
  [certname tags]
  (let [default-row {:certname certname}
        tags        (map #(assoc default-row :name %) tags)]
    (apply sql/insert-records :tags tags)))


(defn persist-catalog!
  "Persist the supplied catalog in the database"
  [{:keys [certname api-version version resources classes edges tags] :as catalog}]
  {:pre [(every? string? #{certname})
         (number? api-version)
         (every? coll? #{classes tags edges})
         (map? resources)]}

  (sql/transaction
   (persist-certname! certname api-version version)
   (persist-classes! certname classes)
   (persist-tags! certname tags)
   (doseq [resource (vals resources)]
     (persist-resource! certname resource))
   (persist-edges! certname edges resources)))
