Useful for connecting your JDBC-using, Heroku-deployed Clojure application to Heroku's postgres service.
To generate a JDBC connection string from a Heroku DATABASE_URL:
(ns example
(:require [heroku-database-url-to-jdbc.core :as h]))
(def database-url "postgres://user:pass@ec2-host:1234/path-to-db")
(h/jdbc-connection-string database-url)
; => "jdbc:postgresql://ec2-host:1234?user=user&password=pass"
To generate a Korma-friendly connection map from a Heroku DATABASE_URL:
(ns example
(:require [heroku-database-url-to-jdbc.core :as h]))
(def database-url "postgres://user:pass@ec2-host:1234/path-to-db")
(h/korma-connection-map database-url)
; {:classname "org.postgresql.Driver"
; :subprotocol "postgresql"
; :user "user"
; :password "pass"
; :subname "//host:1234/path-to-db"
Add to your project.clj
's :dependencies
section:
[heroku-database-url-to-jdbc "0.2.2"]
Copyright © 2014 Ben Orenstein and thoughtbot
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.