pg-connection-string
Advanced tools
Comparing version 2.1.0 to 2.2.0
15
index.js
@@ -38,9 +38,18 @@ 'use strict'; | ||
} | ||
config.host = result.hostname; | ||
if (!config.host) { | ||
// Only set the host if there is no equivalent query param. | ||
config.host = result.hostname; | ||
} | ||
// If the host is missing it might be a URL-encoded path to a socket. | ||
var pathname = result.pathname; | ||
if (!config.host && pathname && /^%2f/i.test(pathname)) { | ||
var pathnameSplit = pathname.split('/'); | ||
config.host = decodeURIComponent(pathnameSplit[0]); | ||
pathname = pathnameSplit.splice(1).join('/'); | ||
} | ||
// result.pathname is not always guaranteed to have a '/' prefix (e.g. relative urls) | ||
// only strip the slash if it is present. | ||
var pathname = result.pathname; | ||
if (pathname && pathname.charAt(0) === '/') { | ||
pathname = result.pathname.slice(1) || null; | ||
pathname = pathname.slice(1) || null; | ||
} | ||
@@ -47,0 +56,0 @@ config.database = pathname && decodeURI(pathname); |
{ | ||
"name": "pg-connection-string", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Functions for dealing with a PostgresSQL connection string", | ||
@@ -31,2 +31,3 @@ "main": "./index.js", | ||
"chai": "^4.1.1", | ||
"coveralls": "^3.0.4", | ||
"istanbul": "^0.4.5", | ||
@@ -33,0 +34,0 @@ "mocha": "^3.5.0" |
@@ -7,3 +7,3 @@ pg-connection-string | ||
[![Build Status](https://travis-ci.org/iceddev/pg-connection-string.svg?branch=master)](https://travis-ci.org/iceddev/pg-connection-string) | ||
[![Coverage Status](https://coveralls.io/repos/iceddev/pg-connection-string/badge.svg?branch=master)](https://coveralls.io/r/iceddev/pg-connection-string?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/iceddev/pg-connection-string/badge.svg?branch=master)](https://coveralls.io/github/iceddev/pg-connection-string?branch=master) | ||
@@ -23,1 +23,52 @@ Functions for dealing with a PostgresSQL connection string | ||
``` | ||
The resulting config contains a subset of the following properties: | ||
* `host` - Postgres server hostname or, for UNIX doamain sockets, the socket filename | ||
* `port` - port on which to connect | ||
* `user` - User with which to authenticate to the server | ||
* `password` - Corresponding password | ||
* `database` - Database name within the server | ||
* `client_encoding` - string encoding the client will use | ||
* `ssl`, either a boolean or an object with properties | ||
* `cert` | ||
* `key` | ||
* `ca` | ||
* any other query parameters (for example, `application_name`) are preserved intact. | ||
## Connection Strings | ||
The short summary of acceptable URLs is: | ||
* `socket:<path>?<query>` - UNIX domain socket | ||
* `postgres://<user>:<password>@<host>:<port>/<database>?<query>` - TCP connection | ||
But see below for more details. | ||
### UNIX Domain Sockets | ||
When user and password are not given, the socket path follows `socket:`, as in `socket:/var/run/pgsql`. | ||
This form can be shortened to just a path: `/var/run/pgsql`. | ||
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=<database>` - sets the database name (urlencoded) | ||
* `encoding=<encoding>` - sets the `client_encoding` property | ||
### TCP Connections | ||
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=<host>` - sets `host` property, overriding the URL's host | ||
* `encoding=<encoding>` - sets the `client_encoding` property | ||
* `ssl=1`, `ssl=true`, `ssl=0`, `ssl=false` - sets `ssl` to true or false, accordingly | ||
* `sslcert=<filename>` - reads data from the given file and includes the result as `ssl.cert` | ||
* `sslkey=<filename>` - reads data from the given file and includes the result as `ssl.key` | ||
* `sslrootcert=<filename>` - 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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8085
82
73
4