   (let [{:keys [entities title]} collection]
     (jdbc/with-db-transaction [tx-conn tenant-conn]
       (when title
-        (update-collection-title tx-conn {:id id :title title}))
+        (db.collection/update-collection-title tx-conn {:id id :title title}))
 
       ;; Replace entity ids
       (when entities
-        (delete-collection-entities tx-conn {:id id})
+        (db.collection/delete-collection-entities tx-conn {:id id})
         (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))))
 
       (fetch tx-conn id))))
 
 (defn delete
   "Delete a collection by id"
   [tenant-conn id]
-  (delete-collection tenant-conn {:id id})
+  (db.collection/delete-collection tenant-conn {:id id})
   (lib/no-content))

    :else
    (jdbc/with-db-transaction [tx-conn tenant-conn]
      (try
        (let [{:keys [id]} (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))))
          (lib/created (second (fetch tx-conn id))))
        (catch SQLException e
          (if (unique-violation? e)

  [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} %)))))

