Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: pg@8.0.3
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: pg@8.1.0
Choose a head ref

Commits on Jul 5, 2014

  1. Initial commit

    phated committed Jul 5, 2014
    Copy the full SHA
    88aafd7 View commit details
  2. initial commit

    phated committed Jul 5, 2014
    Copy the full SHA
    92c1fed View commit details

Commits on Jul 6, 2014

  1. attach port always - ref #604

    phated committed Jul 6, 2014
    Copy the full SHA
    df2a24c View commit details
  2. 0.1.1

    phated committed Jul 6, 2014
    Copy the full SHA
    cb9bee1 View commit details

Commits on Sep 12, 2014

  1. Copy the full SHA
    ba511f7 View commit details

Commits on Sep 13, 2014

  1. Merge pull request #1 from slickmb/task/relative_url

    Support usage of relative urls to set database on the default host
    phated committed Sep 13, 2014
    Copy the full SHA
    c502985 View commit details
  2. 0.1.2

    phated committed Sep 13, 2014
    Copy the full SHA
    245abd6 View commit details

Commits on Sep 26, 2014

  1. Add supporting password with colon

    Ivan Sorokin committed Sep 26, 2014
    Copy the full SHA
    fbdd033 View commit details
  2. Merge pull request #2 from asynxis/master

    Add supporting password with colon
    phated committed Sep 26, 2014
    Copy the full SHA
    0a07e3d View commit details
  3. 0.1.3

    phated committed Sep 26, 2014
    Copy the full SHA
    4c151b9 View commit details

Commits on Oct 12, 2015

  1. Update README.md

    misaxi committed Oct 12, 2015
    Copy the full SHA
    c612dfa View commit details
  2. Merge pull request #6 from misaxi/master

    Update README.md
    phated committed Oct 12, 2015
    Copy the full SHA
    07a7143 View commit details

Commits on Dec 30, 2015

  1. Copy the full SHA
    cdf06ed View commit details

Commits on Apr 27, 2017

  1. feat: add basic typings

    To make this app consumable by Typescript apps a typings file must be present.
    NoNameProvided committed Apr 27, 2017
    Copy the full SHA
    54c2044 View commit details

Commits on Jun 27, 2017

  1. Merge pull request #7 from motiz88/extra-keys

    Copy all but special-cased params from URL query string to config
    monteslu authored Jun 27, 2017
    Copy the full SHA
    e6643e4 View commit details
  2. Merge pull request #10 from NoNameProvided/patch-1

    Add support for Typescript typings
    
    thanks @NoNameProvided  !
    monteslu authored Jun 27, 2017
    Copy the full SHA
    45d8232 View commit details

Commits on Aug 4, 2017

  1. Copy the full SHA
    9ab62ff View commit details

Commits on Aug 30, 2017

  1. Merge pull request #11 from caub/max

    thanks, @caub !
    monteslu authored Aug 30, 2017
    Copy the full SHA
    cf107b0 View commit details
  2. Use mocha, istanbul, and coveralls (#16)

    * some tests
    
    * coveralls and mocha
    
    * coveralls post test hook
    
    * remove done calls
    monteslu authored and warbrett committed Aug 30, 2017
    Copy the full SHA
    1368735 View commit details
  3. 2.0.0

    monteslu committed Aug 30, 2017
    Copy the full SHA
    eafb7ac View commit details

Commits on Nov 22, 2017

  1. Add supporting username and password for socket connections

    This fix adds the ability to use username and password even when using
    a socket.
    ywkim committed Nov 22, 2017
    Copy the full SHA
    279fdea View commit details

Commits on Dec 13, 2017

  1. Fix typings

    benny-medflyt authored Dec 13, 2017
    Copy the full SHA
    929fcb7 View commit details
  2. Copy the full SHA
    ece7645 View commit details

Commits on Apr 18, 2019

  1. Copy the full SHA
    c11dbb1 View commit details

Commits on May 17, 2019

  1. Add support for TLS parameters in URI

    The connection string now supports the following parameters:
    
    - sslcert
    - sslkey
    - sslrootcert
    
    Fixes #25.
    hjr3 committed May 17, 2019
    Copy the full SHA
    e9270e8 View commit details

Commits on May 23, 2019

  1. Merge pull request #26 from hjr3/ssl-support

    Add support for TLS parameters in URI
    hjr3 authored May 23, 2019
    Copy the full SHA
    ac63695 View commit details
  2. Merge pull request #24 from benjie/patch-1

    Only publish the required files
    hjr3 authored May 23, 2019
    Copy the full SHA
    b53c2bd View commit details
  3. Merge pull request #17 from ywkim/master

    Add supporting username and password for socket connections
    hjr3 authored May 23, 2019
    Copy the full SHA
    43114f4 View commit details
  4. ssl=0 is now parses to false

    Fixes #20
    hjr3 committed May 23, 2019
    Copy the full SHA
    7b62226 View commit details
  5. Merge pull request #28 from hjr3/ssl-parsing

    ssl=0 is now parses to false
    hjr3 authored May 23, 2019
    Copy the full SHA
    d7b96e6 View commit details

Commits on May 27, 2019

  1. Update index.d.ts

    benny-medflyt authored May 27, 2019
    Copy the full SHA
    726f620 View commit details

Commits on Jun 11, 2019

  1. Merge pull request #18 from benny-medflyt/patch-1

    Fix typings
    hjr3 authored Jun 11, 2019
    Copy the full SHA
    4db1a7e View commit details

Commits on Jun 19, 2019

  1. 2.1.0

    abowerman committed Jun 19, 2019
    Copy the full SHA
    06c46ac View commit details
  2. Update coveralls badge

    Closes #15
    abowerman committed Jun 19, 2019
    Copy the full SHA
    c9ee9cd View commit details
  3. Merge pull request #30 from iceddev/fix-coverall-badge

    Update coveralls badge
    monteslu authored Jun 19, 2019
    Copy the full SHA
    0f72f29 View commit details
  4. fix readme newline typo

    abowerman committed Jun 19, 2019
    Copy the full SHA
    c75c392 View commit details
  5. actually include coveralls

    abowerman committed Jun 19, 2019
    Copy the full SHA
    e4c1002 View commit details
  6. Merge pull request #31 from iceddev/fix-coverall-badge

    fix readme newline typo
    monteslu authored Jun 19, 2019
    Copy the full SHA
    a483bdf View commit details

Commits on Jan 29, 2020

  1. Copy the full SHA
    0ff40e7 View commit details
  2. Copy the full SHA
    b309db0 View commit details
  3. Copy the full SHA
    7ec9b70 View commit details

Commits on Feb 1, 2020

  1. Merge pull request #34 from danielrozenberg/support-other-socket-modes

    Support more modes to set the host as a socket
    hjr3 authored Feb 1, 2020
    Copy the full SHA
    9b89828 View commit details

Commits on Feb 16, 2020

  1. Include documentation on the URL format in the README

    This summarizes the common forms, but omits some of the more particular,
    and unnecessary forms, such as specifying UNIX domain sockets with
    `pg://` URLs.
    djmitche committed Feb 16, 2020
    Copy the full SHA
    b4e0ba3 View commit details

Commits on Feb 17, 2020

  1. Merge pull request #36 from djmitche/format-docs

    Include documentation on the URL format in the README
    hjr3 authored Feb 17, 2020
    Copy the full SHA
    4356679 View commit details

Commits on Mar 20, 2020

  1. Release v2.2.0

    hjr3 committed Mar 20, 2020
    Copy the full SHA
    5233b3e View commit details

Commits on Apr 28, 2020

  1. Add 'packages/pg-connection-string/' from commit '5233b3e77e396a36813…

    …0709e762fca836290a528'
    
    git-subtree-dir: packages/pg-connection-string
    git-subtree-mainline: 3532880
    git-subtree-split: 5233b3e
    brianc committed Apr 28, 2020
    Copy the full SHA
    4aff01e View commit details
  2. Run lint --fix

    brianc committed Apr 28, 2020
    Copy the full SHA
    3a831fc View commit details
  3. Update test command for travis

    I think the new syntax I'm using here is compatible with `sh`...let's see.
    brianc committed Apr 28, 2020
    Copy the full SHA
    16344cb View commit details
  4. Check for the correct binary

    brianc committed Apr 28, 2020
    Copy the full SHA
    ddf8112 View commit details

Commits on Apr 29, 2020

  1. Merge pull request #2184 from brianc/bmc/pg-connection-string

    Include pg-connection-string into monorepo
    brianc authored Apr 29, 2020
    Copy the full SHA
    e93ecac View commit details
14 changes: 3 additions & 11 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
{
"plugins": [
"prettier"
],
"plugins": ["prettier"],
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"ignorePatterns": [
"node_modules",
"packages/pg-protocol/dist/**/*"
],
"extends": ["plugin:prettier/recommended", "prettier/@typescript-eslint"],
"ignorePatterns": ["node_modules", "coverage", "packages/pg-protocol/dist/**/*"],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ This repo is a monorepo which contains the core [pg](https://github.com/brianc/n
- [pg-pool](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool)
- [pg-cursor](https://github.com/brianc/node-postgres/tree/master/packages/pg-cursor)
- [pg-query-stream](https://github.com/brianc/node-postgres/tree/master/packages/pg-query-stream)
- [pg-connection-string](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string)


## Documenation
1 change: 1 addition & 0 deletions SPONSORS.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ node-postgres is made possible by the helpful contributors from the community as
- [Timescale](https://timescale.com)
- [Nafundi](https://nafundi.com)
- [CrateDB](https://crate.io/)
- [BitMEX](https://www.bitmex.com/app/trade/XBTUSD)

# Supporters

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"test": "yarn lint && yarn lerna exec yarn test",
"build": "yarn lerna exec --scope pg-protocol yarn build",
"pretest": "yarn build",
"lint": "!([[ -e node_modules/.bin/prettier ]]) || eslint '*/**/*.{js,ts,tsx}'"
"lint": "if [ -x ./node_modules/.bin/prettier ]; then eslint '*/**/*.{js,ts,tsx}'; fi;"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.27.0",
2 changes: 2 additions & 0 deletions packages/pg-connection-string/.coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: travis-pro
repo_token: 5F6dODinz9L9uFR6HatKmtsYDoV1A5S2N
26 changes: 26 additions & 0 deletions packages/pg-connection-string/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
package-lock.json
6 changes: 6 additions & 0 deletions packages/pg-connection-string/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.10'
- '6.9'
- '8'
after_success: 'npm run coveralls'
21 changes: 21 additions & 0 deletions packages/pg-connection-string/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Iced Development

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions packages/pg-connection-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
pg-connection-string
====================

[![NPM](https://nodei.co/npm/pg-connection-string.png?compact=true)](https://nodei.co/npm/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/github/iceddev/pg-connection-string/badge.svg?branch=master)](https://coveralls.io/github/iceddev/pg-connection-string?branch=master)

Functions for dealing with a PostgresSQL connection string

`parse` method taken from [node-postgres](https://github.com/brianc/node-postgres.git)
Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)
MIT License

## Usage

```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 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.
14 changes: 14 additions & 0 deletions packages/pg-connection-string/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function parse(connectionString: string): ConnectionOptions

export interface ConnectionOptions {
host: string | null
password?: string
user?: string
port?: string | null
database: string | null | undefined
client_encoding?: string
ssl?: boolean | string

application_name?: string
fallback_application_name?: string
}
89 changes: 89 additions & 0 deletions packages/pg-connection-string/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict'

var url = require('url')
var fs = require('fs')

//Parse method copied from https://github.com/brianc/node-postgres
//Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)
//MIT License

//parses a connection string
function parse(str) {
//unix socket
if (str.charAt(0) === '/') {
var config = str.split(' ')
return { host: config[0], database: config[1] }
}

// url parse expects spaces encoded as %20
var result = url.parse(
/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str) ? encodeURI(str).replace(/\%25(\d\d)/g, '%$1') : str,
true
)
var config = result.query
for (var k in config) {
if (Array.isArray(config[k])) {
config[k] = config[k][config[k].length - 1]
}
}

var auth = (result.auth || ':').split(':')
config.user = auth[0]
config.password = auth.splice(1).join(':')

config.port = result.port
if (result.protocol == 'socket:') {
config.host = decodeURI(result.pathname)
config.database = result.query.db
config.client_encoding = result.query.encoding
return config
}
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.
if (pathname && pathname.charAt(0) === '/') {
pathname = pathname.slice(1) || null
}
config.database = pathname && decodeURI(pathname)

if (config.ssl === 'true' || config.ssl === '1') {
config.ssl = true
}

if (config.ssl === '0') {
config.ssl = false
}

if (config.sslcert || config.sslkey || config.sslrootcert) {
config.ssl = {}
}

if (config.sslcert) {
config.ssl.cert = fs.readFileSync(config.sslcert).toString()
}

if (config.sslkey) {
config.ssl.key = fs.readFileSync(config.sslkey).toString()
}

if (config.sslrootcert) {
config.ssl.ca = fs.readFileSync(config.sslrootcert).toString()
}

return config
}

module.exports = parse

parse.parse = parse
38 changes: 38 additions & 0 deletions packages/pg-connection-string/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "pg-connection-string",
"version": "2.2.2",
"description": "Functions for dealing with a PostgresSQL connection string",
"main": "./index.js",
"types": "./index.d.ts",
"scripts": {
"test": "istanbul cover _mocha && npm run check-coverage",
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git"
},
"keywords": [
"pg",
"connection",
"string",
"parse"
],
"author": "Blaine Bublitz <blaine@iceddev.com> (http://iceddev.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/iceddev/pg-connection-string/issues"
},
"homepage": "https://github.com/iceddev/pg-connection-string",
"devDependencies": {
"chai": "^4.1.1",
"coveralls": "^3.0.4",
"istanbul": "^0.4.5",
"mocha": "^3.5.0"
},
"files": [
"index.js",
"index.d.ts"
]
}
1 change: 1 addition & 0 deletions packages/pg-connection-string/test/example.ca
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example ca
1 change: 1 addition & 0 deletions packages/pg-connection-string/test/example.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example cert
1 change: 1 addition & 0 deletions packages/pg-connection-string/test/example.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example key
Loading