   "Given table name, fetch all rows from database and return
   as HTML table."
   [dbname table]
-  (let [rows (jdbc/query DB [(build-query dbname table)])]
+  (let [_ (pprint (build-query dbname table))
+		rows (jdbc/query DB [(build-query dbname table)])]
 	(h/html
 	 [:p {:class "count"} (str (count rows) " rows found")]
 	 [:table

	  s)))


(defn build-query
  "Given db & table, return query string that retrieves table data and
  looks up display fields from related tables."
  [dbname table]
  (let [constraints (filter #(= table (:table_name %))(fk-constraints DB dbname))
		sel (for [{:keys [referenced_table_name column_name]} constraints]
			  (str ", " referenced_table_name "."
				   (get display-fields referenced_table_name)
				   " AS " column_name))
		joins (for [{:keys [referenced_table_name referenced_column_name table_name column_name]} constraints]
				(str " INNER JOIN " referenced_table_name " ON " table_name "." column_name
					 " = " referenced_table_name "." referenced_column_name))]
	(str "SELECT " table ".*" (apply str sel) " FROM " table (apply str joins))
	))



  "Returns list of table names for current db."
  []
  (map last (map first (vec (show-tables DB)))))


(defn prettify
