Fixes #137 by adding user/password arities to get-connection
Also calls `.getConnection` with user/password under the hood if those are present in the `opts` hash map.
This commit is contained in:
parent
e006be8ac4
commit
049f34e311
3 changed files with 18 additions and 3 deletions
|
|
@ -3,6 +3,7 @@
|
|||
Only accretive/fixative changes will be made from now on.
|
||||
|
||||
Changes made to **develop** since the 1.1.569 release:
|
||||
* Fix #137 by adding support for specifying username and password per-connection (if your datasource supports this).
|
||||
* Document SQLite handling of `bool` and `bit` columns in a new **Tips & Tricks** section, inspired by #134.
|
||||
* Address #133 by adding `:return-generated-keys` as an option on `execute-batch!`.
|
||||
|
||||
|
|
|
|||
|
|
@ -144,13 +144,23 @@
|
|||
and applies the `:auto-commit` and/or `:read-only` options, if provided.
|
||||
|
||||
If you call `get-connection` on anything else, it will call `get-datasource`
|
||||
first to try to get a `DataSource`, and then call `get-connection` on that."
|
||||
first to try to get a `DataSource`, and then call `get-connection` on that.
|
||||
|
||||
If you want different per-connection username/password values, you can
|
||||
either put `:user` and `:password` into the `opts` hash map or pass them
|
||||
as positional arguments."
|
||||
(^java.sql.Connection
|
||||
[spec]
|
||||
(p/get-connection spec {}))
|
||||
(^java.sql.Connection
|
||||
[spec opts]
|
||||
(p/get-connection spec opts)))
|
||||
(p/get-connection spec opts))
|
||||
(^java.sql.Connection
|
||||
[spec user password]
|
||||
(p/get-connection spec {:user user :password password}))
|
||||
(^java.sql.Connection
|
||||
[spec user password opts]
|
||||
(p/get-connection spec (assoc opts :user user :password password))))
|
||||
|
||||
(defn prepare
|
||||
"Given a connection to a database, and a vector containing SQL and any
|
||||
|
|
|
|||
|
|
@ -341,7 +341,11 @@
|
|||
via reflection, e.g., :autoCommit, :readOnly, :schema..."
|
||||
^Connection
|
||||
[^DataSource datasource opts]
|
||||
(let [^Connection connection (.getConnection datasource)]
|
||||
(let [^Connection connection (if (and (:user opts) (:password opts))
|
||||
(.getConnection datasource
|
||||
(:user opts)
|
||||
(:password opts))
|
||||
(.getConnection datasource))]
|
||||
;; fast, specific option handling:
|
||||
(when (contains? opts :auto-commit)
|
||||
(.setAutoCommit connection (boolean (:auto-commit opts))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue