Functions for dealing with a PostgresSQL connection string
npm install @benjie/pg-connection-stringpg-connection-string
====================



Functions for dealing with a PostgresSQL connection string
parse method taken from node-postgres
Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)
MIT License
``js
var parse = require('pg-connection-string').parse;
var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
`
The resulting config contains a subset of the following properties:
* host - Postgres server hostname or, for UNIX doamain sockets, the socket filenameport
* - port on which to connectuser
* - User with which to authenticate to the serverpassword
* - Corresponding passworddatabase
* - Database name within the serverclient_encoding
* - string encoding the client will usessl
* , either a boolean or an object with propertiescert
* key
* ca
* application_name
* any other query parameters (for example, ) are preserved intact.
The short summary of acceptable URLs is:
* socket: - UNIX domain socketpostgres://
* - TCP connection
But see below for more details.
When user and password are not given, the socket path follows socket:, as in socket:/var/run/pgsql./var/run/pgsql
This form can be shortened to just a path: .
When user and password are given, they are included in the typical URL positions, with an empty host, as in socket://user:pass@/var/run/pgsql.
Query parameters follow a ? character, including the following special query parameters:
* db= - sets the database name (urlencoded)encoding=
* - sets the client_encoding property
TCP connections to the Postgres server are indicated with pg: or postgres: schemes (in fact, any scheme but socket: is accepted).
If username and password are included, they should be urlencoded.
The database name, however, should not be urlencoded.
Query parameters follow a ? character, including the following special query parameters:host=
* - sets host property, overriding the URL's hostencoding=
* - sets the client_encoding propertyssl=1
* , ssl=true, ssl=0, ssl=false - sets ssl to true or false, accordinglysslcert=
* - reads data from the given file and includes the result as ssl.certsslkey=
* - reads data from the given file and includes the result as ssl.keysslrootcert=
* - reads data from the given file and includes the result as ssl.ca
A bare relative URL, such as salesdata`, will indicate a database name while leaving other properties empty.