     (fn [db ops active?]
       (when active?
         (doto js/Mousetrap
-          (.bind "alt+d" #((:preview-table ops) (@selected "name")))
+          (.bind "alt+d" #(.preview ops (@selected "name")))
           (.bind "/" #(swap! search? not))
           (.bind "esc" #(reset! search? false))))
       [:div.full-height.panel.panel-default


(defn sql-panel [db ops active?]
  (let [cm (atom nil)
        exec-sql (fn[] ((ops :exec-sql)
                        (if (empty? (.getSelection @cm))
                          (.getValue @cm) (.getSelection @cm))))]
    (fn[db ops]

       [:div.panel-footer]])))


(deftype ConsoleControl [data-tabs active-tab q-id]
  Object
  (preview [_ tbl]
    (when-not (some #(= tbl (:id %)) @data-tabs)
      (.log js/console "adding table " tbl)
      (swap! data-tabs conj {:id tbl :raw-sql (str "select * from " tbl)}))
    (reset! active-tab tbl))

  (exec-sql [_ sql]
    (let [id (str "Query #" (swap! q-id inc))]
      (swap! data-tabs conj {:id id :raw-sql sql})
      (reset! active-tab id)))

  (delete-tab [_ t]
    (swap! data-tabs (partial remove #(= t %)))
    (if (= (:id t) @active-tab)
      (reset! active-tab (:id (first @data-tabs))))))

(defn mk-console-control [data-tabs active-tab]
  (let [q-id (atom 0)]
    (ConsoleControl. data-tabs active-tab q-id)))

(defn db-console [db active?]
  (let [active-tab (atom nil)
        data-tabs (atom [])
        ops (mk-console-control data-tabs active-tab)]
    (fn[db active?]
      [st/horizontal-splitter {:split-at 240}
       [db-objects db ops active?]
