Skip to content
Snippets Groups Projects
Commit 5d1fa636 authored by Cam Saul's avatar Cam Saul
Browse files

Move class->base-type mapping into driver since mongo driver *and*

generic SQL will share it.
Add Mongo lib dependency
parent 188adb07
Branches
Tags
No related merge requests found
......@@ -28,6 +28,7 @@
[com.cemerick/friend "0.2.1"] ; auth library
[com.h2database/h2 "1.4.186"] ; embedded SQL database
[com.mattbertolini/liquibase-slf4j "1.2.1"]
[com.novemberain/monger "2.1.0"] ; MongoDB Driver
[compojure "1.3.3"] ; HTTP Routing library built on Ring
[environ "1.0.0"] ; easy environment management
[hiccup "1.0.5"] ; HTML templating
......
......@@ -14,6 +14,8 @@
(declare -dataset-query query-fail query-complete save-query-execution)
;; ## Constants
(def ^:const available-drivers
"DB drivers that are available as a dictionary. Each key is a driver with dictionary of attributes.
ex: `:h2 {:id \"h2\" :name \"H2\"}`"
......@@ -22,7 +24,23 @@
:example "file:[filename]"}
:postgres {:id "postgres"
:name "Postgres"
:example "host=[ip address] port=5432 dbname=examples user=corvus password=******"}})
:example "host=[ip address] port=5432 dbname=examples user=corvus password=******"}
:mongo {:id "mongo"
:name "MongoDB"
:example "mongodb://password:username@127.0.0.1:27017/db-name"}})
(def ^:const class->base-type
"Map of classes returned from DB call to metabase.models.field/base-types"
{java.lang.Boolean :BooleanField
java.lang.Double :FloatField
java.lang.Float :FloatField
java.lang.Integer :IntegerField
java.lang.Long :IntegerField
java.lang.String :TextField
java.math.BigDecimal :DecimalField
java.math.BigInteger :BigIntegerField
java.sql.Date :DateField
java.sql.Timestamp :DateTimeField})
;; ## Driver Lookup
......@@ -208,7 +226,6 @@
(select-keys [:id :uuid])
(merge query-result)))
(defn save-query-execution
[{:keys [id] :as query-execution}]
(if id
......
......@@ -6,22 +6,10 @@
(korma [core :as korma]
db)
[metabase.db :refer [sel]]
[metabase.driver :as driver]
[metabase.driver.generic-sql.util :refer :all]
[metabase.models.database :refer [Database]]))
(def ^:const class->base-type
"Map of classes returned from DB call to metabase.models.field/base-types"
{java.lang.Boolean :BooleanField
java.lang.Double :FloatField
java.lang.Float :FloatField
java.lang.Integer :IntegerField
java.lang.Long :IntegerField
java.lang.String :TextField
java.math.BigDecimal :DecimalField
java.math.BigInteger :BigIntegerField
java.sql.Date :DateField
java.sql.Timestamp :DateTimeField})
(def ^:dynamic *timezone->set-timezone-sql*
" This function is called whenever `timezone` is specified in a native query, at the beginning of
the DB transaction.
......@@ -38,8 +26,8 @@
"Attempt to match a value we get back from the DB with the corresponding base-type`."
[v]
(if-not v :UnknownField
(or (class->base-type (type v))
(throw (ApiException. (int 500) (format "Missing base type mapping for %s in metabase.driver.generic-sql.native/class->base-type. Please add an entry."
(or (driver/class->base-type (type v))
(throw (ApiException. (int 500) (format "Missing base type mapping for %s in driver/class->base-type. Please add an entry."
(str (type v))))))))
(defn process-and-run
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment