Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created March 9, 2015 03:34
Show Gist options
  • Save apeckham/ecdf66823711dbdc3948 to your computer and use it in GitHub Desktop.
Save apeckham/ecdf66823711dbdc3948 to your computer and use it in GitHub Desktop.
elixir postgrex connect to database_url from environment variable
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