Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to parse extra parameters to mysql jdbc #374

Open
wants to merge 2 commits into
base: release_0.4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject korma "0.4.3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change the project name.

(defproject mprokopov/korma "0.4.4"
:description "Tasty SQL for Clojure"
:url "http://github.com/korma/Korma"
:mailing-list {:name "Korma Google Group"
Expand Down
17 changes: 13 additions & 4 deletions src/korma/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,28 @@
:make-pool? make-pool?}
(dissoc opts :host :port)))

(defn- parse-mysql-extra
"parse extra mysql map and returns string could be appended to :subname
in format '?key1=value1&key2=value2 ...'"
[m]
(when m
(->> (map (fn [[k v]] (str (name k) "=" v)) m)
(clojure.string/join "&")
(str "?"))))

(defn mysql
"Create a database specification for a mysql database. Opts should include keys
for :db, :user, and :password. You can also optionally set host and port.
Delimiters are automatically set to \"`\"."
[{:keys [host port db make-pool?]
:or {host "localhost", port 3306, db "", make-pool? true}
[{:keys [host port db make-pool? extra]
:or {host "localhost", port 3306, db "", make-pool? true, extra nil}
:as opts}]
(merge {:classname "com.mysql.jdbc.Driver" ; must be in classpath
:subprotocol "mysql"
:subname (str "//" host ":" port "/" db)
:subname (str "//" host ":" port "/" db (parse-mysql-extra extra))
:delimiters "`"
:make-pool? make-pool?}
(dissoc opts :host :port :db)))
(dissoc opts :host :port :db :extra)))

(defn vertica
"Create a database specification for a vertica database. Opts should include keys
Expand Down