LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
285 stars 39 forks source link

clojureql should support connecting with URI #143

Closed rbxbx closed 6 years ago

rbxbx commented 10 years ago

The underlying jdbc driver supports several different methods of connecting (https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc.clj#L144)

There's no reason clojureql shouldn't take advantage of this as well. It's especially useful if connecting with something like Heroku, where you're going to be pulling your connection information out of an environment variable.

It's a pretty trivial fix (at least for the basic case, there may be a better way to do this)

diff --git a/src/clojureql/connectivity.clj b/src/clojureql/connectivity.clj
index 00056b1..c0ff9be 100644
--- a/src/clojureql/connectivity.clj
+++ b/src/clojureql/connectivity.clj
@@ -46,8 +46,8 @@

(jdbc/find-connection) ; an already open c.j.jdbc connection takes precedence
(func)
-
-    (map? con-info) ; then we try a passed connection info (presumably associated with some table in the query)
+
+    (or (map? con-info) (string? con-info) (instance? java.net.URI con-info)); then we try a passed connection info (presumably associated with some table in the query)
(jdbc/with-connection con-info
(.setAutoCommit (jdbc/find-connection)
        (:auto-commit con-info true))

I made some attempts to get tests written around this, but was having some difficulty with the test-suite. I've tested these changes within my application and it all seems to work well.

Cheers, Robert

LauJensen commented 6 years ago

Thanks, Ive pushed a change that incorporates this and passes the tests.