Created
March 9, 2015 03:34
-
-
Save apeckham/ecdf66823711dbdc3948 to your computer and use it in GitHub Desktop.
elixir postgrex connect to database_url from environment variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uri = System.get_env("DATABASE_URL") |> URI.parse | |
[username, password] = String.split(uri.userinfo, ":") | |
{:ok, pid} = Postgrex.Connection.start_link \ | |
hostname: uri.host, | |
username: username, | |
password: password, | |
database: uri.path |> String.lstrip(?/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment