A tiny little script for psql and database URL's
I got tired of taking database URL's in the format postgres://user:password@host:port/database
and manually pulling out the arguments in order to use psql
, so I wrote this:
#!/usr/bin/env ruby
require 'uri'
u = URI.parse ARGV.first
exec "PGPASSWORD=#{u.password} psql -U #{u.user} -h #{u.host} -p #{u.port} #{u.path.sub('/', '')}"
I saved it in /usr/local/bin/psqlu
, so I can call it like this:
psqlu postgres://user:password@host:port/database
Written by Lawrence Wang
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#