 
   For example, if the source of an edge is {'type' 'Foo' 'title' 'bar'},
   then we'll lookup a resource with that key and use its hash."
-  [catalog-hash edges refs-to-hashes]
-  {:pre [(string? catalog-hash)
+  [catalog-id edges refs-to-hashes]
+  {:pre [(number? catalog-id)
          (coll? edges)
          (map? refs-to-hashes)]}
-  (let [the-sql "INSERT INTO edges (catalog_id,source,target,type) SELECT id,?,?,? FROM catalogs WHERE hash=?"
+  (let [the-sql "INSERT INTO edges (catalog_id,source,target,type) VALUES (?,?,?,?)"
         rows    (for [{:keys [source target relationship]} edges
                       :let [source-hash (refs-to-hashes source)
                             target-hash (refs-to-hashes target)
                             type        (name relationship)]]
-                  [source-hash target-hash type catalog-hash])]
+                  [catalog-id source-hash target-hash type])]
     (apply sql/do-prepared the-sql rows)))
 
 (defn add-catalog!

    (pos? (first replaced))))

(defn add-catalog-metadata!
  "Given some catalog metadata, persist it in the db"
  [hash api-version catalog-version transaction-uuid]
  {:pre [(string? hash)
         (number? api-version)
         (string? catalog-version)
         ((some-fn nil? string?) transaction-uuid)]}
  (sql/insert-record :catalogs {:hash             hash
                                :api_version      api-version
                                :catalog_version  catalog-version
                                :transaction_uuid transaction-uuid}))

(defn update-catalog-metadata!
  "Given some catalog metadata, update the db"


  The result map has the following format:

    {:resource [[<catalog id> <resouce hash> <type> <title> <tags> <exported?> <sourcefile> <sourceline>] ...]
     :parameters [[<resource hash> <name> <value>] ...]
     :parameters_cache [[<resource hash> <parameters>] ...]}

