PG::URL

Postgres connection string builder gem with construction through a prompt or Ruby method.

Installation

Add this line to your application's Gemfile:

gem 'pg-url'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pg-url

Usage

Method

  • PG::URL.new (alias PG::URL[])

Constructs and returns a connection string built from the parameters given.

Parameters

The parameters indicated with a check mark are required.

  • [ ] host - The host address that the database is hosted on. If no host is specified, then localhost is used as the host.
  • [ ] port - The port of the host address. If no port is specified (and no host is specified), then the default Postgres port 5432 will be used on localhost.
  • [x] database - The name of the Postgres database.
  • [x] username - The username of a user on the Postgres table
  • [ ] password - The password for the user specified by the username parameter. If the user does not have a password, this parameter can be left empty.

Examples

require 'pg/url'

PG::URL.new(host: '192.168.2.1', database: 'db', username: 'root', password: 'test')
#=> "postgres://root:[email protected]/db"

PG::URL[host: 'pg-host.com', port: 3755, database: 'db', username: 'root']
#=> "postgres://[email protected]:3755/db"

conn = {port: '4321', database: 'users', username: 'K&fB2y'}
PG::URL[conn]
#=> "postgres://K&fB2y@localhost:4321/users"

Prompt

PG::URL.prompt constructs and returns a connection string built from details specified by the user in a prompt.

Development

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/eonu/pg-url.