Skip to content

Instantly share code, notes, and snippets.

@kbaum
Last active December 13, 2017 17:10
Show Gist options
  • Save kbaum/880f5639e425268181d9ac0933e9a286 to your computer and use it in GitHub Desktop.
Save kbaum/880f5639e425268181d9ac0933e9a286 to your computer and use it in GitHub Desktop.
Pull out attributes of a postgres url
#!/usr/bin/env ruby
require 'uri'
uri = URI(ARGV[0])
props = {username: uri.user, password: uri.password, host: uri.host, port: uri.port, database: uri.path[1..-1]}
props.each do |key, value|
puts "#{key}=#{props[key]}"
end

I use this for connecting to a postgres database from navicat. Not sure if there is a better way. For example:

db_params `heroku config:get DATABASE_URL -a vts-production-replica`

Outputs:

username=xdfkdfsi
password=xxxxxxkdfkslsldksokdksj9dsa
host=ec2-42-95-244-210.compute-1.amazonaws.com
port=5432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment