Skip to content

Commit

Permalink
Extract subprotocol to options mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
immoh committed Jul 21, 2015
1 parent 2bd94be commit da45ac8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/korma/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@
"sqlite" "org.sqlite.JDBC"
"h2" "org.h2.Driver"})

(def ^:private subprotocol->options {"mysql" {:delimiters "`"}
"vertica" {:delimiters "\""}})

(defn- complete-spec [{:keys [subprotocol] :as spec}]
(merge
{:classname (subprotocol->classname (first (clojure.string/split subprotocol #":")))
:make-pool? true}
spec))
(let [lookup-key (first (clojure.string/split subprotocol #":"))]
(merge
{:classname (subprotocol->classname lookup-key)
:make-pool? true}
(subprotocol->options lookup-key)
spec)))

(defn firebird
"Create a database specification for a FirebirdSQL database. Opts should include
Expand Down Expand Up @@ -187,8 +192,7 @@
:or {host "localhost", port 3306, db ""}
:as opts}]
(complete-spec (merge {:subprotocol "mysql"
:subname (str "//" host ":" port "/" db)
:delimiters "`"}
:subname (str "//" host ":" port "/" db)}
(dissoc opts :host :port :db))))

(defn vertica
Expand All @@ -199,8 +203,7 @@
:or {host "localhost", port 5433, db ""}
:as opts}]
(complete-spec (merge {:subprotocol "vertica"
:subname (str "//" host ":" port "/" db)
:delimiters "\""}
:subname (str "//" host ":" port "/" db)}
(dissoc opts :host :port :db))))

(defn mssql
Expand Down

0 comments on commit da45ac8

Please sign in to comment.