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

Add MariaDB support #384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion src/korma/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@
:subname db}
(dissoc opts :db)))

(defn mariadb
"Create a database specification for a mariadb database. Opts should include keys
for :db, :user, and :password. You can also optionally set host and port.
Delimiters are automatically set to \"`\"."
[{:keys [user password host port db]
:or {user "root" password "" host "localhost", port 3306, db ""}
:as opts}]
(merge {:classname "org.mariadb.jdbc.Driver"
:subprotocol "mariadb"
:subname (str "//" host ":" port "/" db "?user=" user "&password=" password "")}
(dissoc opts :host :port :db)))

(defmacro transaction
"Execute all queries within the body in a single transaction.
Optionally takes as a first argument a map to specify the :isolation and :read-only? properties of the transaction."
Expand Down Expand Up @@ -289,7 +301,7 @@

(defn- exec-sql [{:keys [results sql-str params]}]
(let [keys (get-in *current-db* [:options :naming :keys])
sql-params (apply vector sql-str params)]
sql-params (apply vector (clojure.string/replace sql-str #"\"" "`") params)]
(case results
:results (jdbc/query *current-conn* sql-params {:identifiers keys})
:keys (jdbc/db-do-prepared-return-keys *current-conn* sql-params)
Expand Down