Skip to content

Instantly share code, notes, and snippets.

@flyingmachine
Created November 2, 2012 22:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flyingmachine/4004807 to your computer and use it in GitHub Desktop.
Save flyingmachine/4004807 to your computer and use it in GitHub Desktop.
clojure korma heroku db connection
(defdb db
(if (System/getenv "DATABASE_URL")
(let [db-uri (java.net.URI. (System/getenv "DATABASE_URL"))
user-and-password (clojure.string/split (.getUserInfo db-uri) #":")]
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:user (get user-and-password 0)
:password (get user-and-password 1) ; may be nil
:subname (if (= -1 (.getPort db-uri))
(format "//%s%s" (.getHost db-uri) (.getPath db-uri))
(format "//%s:%s%s" (.getHost db-uri) (.getPort db-uri) (.getPath db-uri)))})
(postgres
{:db "gratefulplace-development"
:user "daniel"
:password ""
;;OPTIONAL KEYS
:host "localhost"})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment