     :else
     (jdbc/with-db-transaction [tx-conn tenant-conn]
       (try
-        (let [{:keys [id]} (create-collection tenant-conn {:title title})]
+        (let [{:keys [id]} (db.collection/create-collection tenant-conn {:title title})]
           (when entities
             (doseq [entity (categorize-entities tx-conn entities)]
-              (insert-collection-entity tx-conn (assoc entity :collection-id id))))
+              (db.collection/insert-collection-entity tx-conn (assoc entity :collection-id id))))
           (lib/created (second (fetch tx-conn id))))
         (catch SQLException e
           (if (unique-violation? e)

(ns akvo.lumen.lib.collection
  (:refer-clojure :exclude [update])
  (:require [akvo.lumen.lib :as lib]
            [clojure.java.jdbc :as jdbc]
            [clojure.set :as set]
            [hugsql.core :as hugsql])

  [conn entities]
  (let [entity-array (text-array conn entities)]
    (->> (concat
           (db.collection/fetch-dataset-ids conn {:ids entity-array})
           (db.collection/fetch-visualisation-ids conn {:ids entity-array})
           (db.collection/fetch-dashboard-ids conn {:ids entity-array})
           (db.collection/fetch-raster-dataset-ids conn {:ids entity-array}))
      (map #(merge {:dataset-id nil :visualisation-id nil :dashboard-id nil
                    :raster-dataset-id nil} %)))))

