 
 (defn- db->korma-db
   "Return a Korma DB spec for Metabase DATABASE."
-  ([database]
-   (db->korma-db (driver/engine->driver (:engine database)) (:details database)))
-  ([driver details]
-   (assoc (kx/create-db (connection-details->spec driver details))
-          :pool (db->jdbc-connection-spec driver details))))
-
-(defn- table+db->entity [{schema :schema, table-name :name} db]
-  (k/database (kx/create-entity [schema table-name]) db))
+  [database]
+  (let [driver  (driver/engine->driver (:engine database))
+        details (:details database)]
+    (assoc (kx/create-db (connection-details->spec driver details))
+      :pool (db->jdbc-connection-spec database))))
 
 (defn korma-entity
   "Return a Korma entity for [DB and] TABLE.

   :current-datetime-fn     (constantly (k/sqlfn* :NOW))
   :excluded-schemas        (constantly nil)
   :field->alias            (u/drop-first-arg name)
   :get-connection-for-sync db->connection
   :prepare-value           (u/drop-first-arg :value)
   :set-timezone-sql        (constantly nil)
   :stddev-fn               (constantly :STDDEV)})

    (-> (sel :one Table :id 100)
        korma-entity
        (select (aggregate (count :*) :count)))"
  ([table]    (korma-entity (table/database table) table))
  ([db table] (let [{schema :schema, table-name :name} table]
                (k/database
                  (kx/create-entity [schema table-name])
                  (db->korma-db db)))))
