Allow URI connection string

Issue #189 resolved
Chris Bandy
created an issue

libpq has supported URI connection string since PostgreSQL 9.2, Sep 2012.

It would be great to be able to do the following:

conn = PG.connect('postgresql://user:pass@postgresql.lxc:5432/development?sslmode=require')

Discussion on mailing list: https://groups.google.com/forum/#!topic/ruby-pg/QyueL4oCq1M

Comments (6)

  1. Eric Radman

    I was able to work around this problem by manually converting the connection string to parameters:

    require "uri"
    conn = URI.parse( ENV['PGHOST'] )
    PG.connect(
      :host => URI.decode(conn.host),
      :port => conn.port,
      :user => conn.user ? conn.user : ENV['USER'],
      :password => conn.password,
      :dbname => conn.path[1..-1]
    )
    

    Unfortunately adding this kind of parsing into individual applications is almost certainly incomplete (this doesn't handle query string arguments, for example) so official support would be very valuable.

  2. Log in to comment