Skip to content

Commit

Permalink
Merge pull request #63 from metabase/configurable-jdbc-options
Browse files Browse the repository at this point in the history
Make options passed to jdbc/query and jdbc/execute! configurable
  • Loading branch information
camsaul authored Aug 20, 2019
2 parents fa0ffb2 + b984562 commit a8e4ebe
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/toucan/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@
[db-connection-map]
(reset! default-db-connection db-connection-map))

(defonce ^:private default-jdbc-options
;; FIXME: This has already been fixed in `clojure.java.jdbc`, so
;; this option can be removed when using >= 0.7.10.
(atom {:identifiers u/lower-case}))

(defn set-default-jdbc-options!
"Set the default options to be used for all calls to `clojure.java.jdbc/query` or `execute!`."
[jdbc-options]
(reset! default-jdbc-options jdbc-options))



;;; TRANSACTION & CONNECTION UTIL FNS
;;; ==================================================================================================================
Expand Down Expand Up @@ -273,9 +284,7 @@
[honeysql-form & {:as options}]
(jdbc/query (connection)
(honeysql->sql honeysql-form)
;; FIXME: This has already been fixed in `clojure.java.jdbc`, so
;; this option can be removed when using >= 0.7.10.
(into options {:identifiers u/lower-case})))
(merge @default-jdbc-options options)))

(defn reducible-query
"Compile `honeysql-from` and call `jdbc/reducible-query` against the application database. Options are passed along
Expand Down Expand Up @@ -412,7 +421,7 @@
`options` are passed directly to `jdbc/execute!` and can be things like `:multi?` (default `false`) or
`:transaction?` (default `true`)."
[honeysql-form & {:as options}]
(jdbc/execute! (connection) (honeysql->sql honeysql-form) options))
(jdbc/execute! (connection) (honeysql->sql honeysql-form) (merge @default-jdbc-options options)))

(defn- where
"Generate a HoneySQL `where` form using key-value args.
Expand Down

0 comments on commit a8e4ebe

Please sign in to comment.