seancorfield / next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/
Eclipse Public License 1.0
760 stars 90 forks source link

Allow dbtype aliases for jdbc urls? #143

Closed stelcodes closed 3 years ago

stelcodes commented 3 years ago

Hi Sean (and others)! I'm running into an exception because the raw JDBC URL sourced from my heroku environment contains just "postgres" and not "postgresql" for the dbtype portion. Currently it seems that next.jdbc only supports dbtype aliasing for "postgres" if the value is passed using the :dbtype keyword.

Because of this I'm getting java.sql.SQLException: No suitable driver found

I see that next.jdbc doesn't make any attempt to parse a raw JDBC URL, so adding something like this might be clunky, but possible helpful enough to warrant? I'd love to take a stab at it if a change like this is welcome.

In the meantime I will change the heroku JDBC URL to read "jdbc:postgresql://..." before handing it to next.jdbc.

This is the relevant code line: https://github.com/seancorfield/next-jdbc/blob/67eadf1bbb9b5878a65924a6535f529f6a40c93b/src/next/jdbc/connection.clj#L161

btw I enjoyed your defn podcast interview! :)

seancorfield commented 3 years ago

If you have a URL, you shouldn't be using :dbtype. That's when you should use {:jdbcUrl "..."} and the JDBC spec says it should begin with jdbc: and then the type should be identifiable by the JDBC system itself -- in other words, next.jdbc does nothing with JDBC URLs. The aliases that next.jdbc allows for :dbtype are completely irrelevant when you're using a JDBC URL.

If Heroku is giving you a JDBC URL, it should just work with :jdbcUrl -- that's up to the JDBC driver, not next.jdbc.

stelcodes commented 3 years ago

Ahh ok! I see now. Heroku isn't actually giving me a jdbc url, it's formatted slightly differently. I must parse it for the host, port, username, and password.

Apparently you can give clojure.jdbc their database url and it handles it fine. If only they would update their clojure docs to use next.jdbc. That's where I got tripped up. Thanks for pointing me in the right direction.