 (defn get-run
   "Returns the data for the given run-id"
   [conn run-id]
-  (first
-    (j/query conn
-      ["SELECT run.*, project.id project_id FROM run
-       JOIN suite ON run.suite_id = suite.id JOIN project ON suite.project_id = project.id
-       WHERE project.id = suite.project_id AND suite.id = run.suite_id AND run.id = ?" run-id]
-      :row-fn format-dates
-      :identifiers ident-fn)))
+  (query-single conn
+    ["SELECT run.*, project.id project_id FROM run
+          JOIN suite ON run.suite_id = suite.id JOIN project ON suite.project_id = project.id
+          WHERE project.id = suite.project_id AND suite.id = run.suite_id AND run.id = ?" run-id]
+    :row-fn format-dates))
 
 (def ^:private get-suite-runs-sql
   "SELECT run.* FROM run JOIN suite ON suite.id = run.suite_id

                                :diff-image  diff-image-id})))

(defn get-diff [conn run-id diff-id]
  (first
    (j/query conn
      ["SELECT diff.* FROM diff
      JOIN analysis ON analysis.id = diff.analysis_id
      JOIN run ON run.id = analysis.run_id
      WHERE run.id = ? AND diff.id = ?" run-id diff-id]
      :identifiers ident-fn)))

(defn update-diff-status! [conn diff-id status]
  (update! conn :diff {:status status} ["id = ?" diff-id]))


;; Baseline
(defn get-baseline-screenshot [conn suite-id screenshot-name {:keys [os browser resolution]}]
  (query-single conn
    ["SELECT screenshot.* FROM screenshot
                 JOIN baseline_screenshot ON screenshot.id = baseline_screenshot.screenshot_id
                 JOIN baseline ON baseline_screenshot.baseline_id = baseline.id
                 JOIN suite ON baseline.suite_id = suite.id
                 WHERE suite.id = ? AND screenshot.screenshot_name = ?
                 AND screenshot.os = ? AND screenshot.resolution = ?
                 AND screenshot.browser = ?" suite-id screenshot-name os resolution browser]))

(defn get-baseline [conn suite-id]
  (query-single conn ["SELECT * FROM baseline WHERE suite_id = ?" suite-id]))

(defn create-baseline-screenshot!
  "Adds the given screenshot-id to the given baseline."
