Skip to content

Instantly share code, notes, and snippets.

@LispyAriaro
Forked from flyingmachine/gist:4004807
Last active September 17, 2015 01:16
Show Gist options
  • Save LispyAriaro/803e5e37cb735da6dbb8 to your computer and use it in GitHub Desktop.
Save LispyAriaro/803e5e37cb735da6dbb8 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