2.7.0 • Published 9 months ago

pg-connection-string v2.7.0

Weekly downloads
2,345,541
License
MIT
Repository
github
Last release
9 months ago

pg-connection-string

NPM

Build Status Coverage Status

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

Usage

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:

  • user - User with which to authenticate to the server
  • password - Corresponding password
  • host - Postgres server hostname or, for UNIX domain sockets, the socket filename
  • port - port on which to connect
  • database - Database name within the server
  • client_encoding - string encoding the client will use
  • ssl, either a boolean or an object with properties
    • rejectUnauthorized
    • 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
  • sslmode=<sslmode>
    • sslmode=disable - sets ssl to false
    • sslmode=no-verify - sets ssl to { rejectUnauthorized: false }
    • sslmode=prefer, sslmode=require, sslmode=verify-ca, sslmode=verify-full - sets ssl to true
  • 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.

pgrelay-restreach-ad-analyserbatch-processing-servicepostgres-testing-libraryaloha.tech-backend@xavo/cli@mui/studiofaros-canonical-reports@everything-registry/sub-chunk-2429@zcut/sequelizetamidi-sequelize-coret1t-pg-audit-logtablewaretest-db-servicewith-conn-pgxdms3teapackage-tatespoorman297stateslangstrapi-neon-tech-db-branchestestx-postgres-keywords@daita/core@collectai/node-waitfordb@cannypack/sequelize@roux-xyz/ponder-coreitty-postgresjigsaw-importerjson-categorizejsqltestjoist-utilsinsights-core@ashkuc/unique-harvester@purnasatria/directus-extension-document-interfacesparbuchknex-pgsql-edgeruntimeknex-lukepg-dns-passivesequelize-working-poolstreaka-knextwo-authtoolbox-backendtoolbox-backend-esutdelenitiunleash-serverunleash-server-openapiturio-api--nodejs@aidenlx/knex@apexdevtools/benchmarker@aptos-labs/aptos-processor-sdk@atlantis-of-code/aoc-cli@asiz33/smartblok-vendure-plugin@backstage/backend-test-utils@backstage/backend-defaults@beequeue/knex@adtechiumpublic/knex@bluaxolotl/sequelize@cardano-sdk/cardano-services@cardstack/plugin-utils@capaj/knex@cheqd/studio@cjmaio/knex@cheqd/credential-service@abradley2/sequelize@adam3am/monika@mondomob/graphile-scheduler@dawadk/common@deepstructure/sdk@dicarlo/knex@creditiq/sequelizeward-node-corewebplatformwebliftunique-sdkuptime-kuma@fdy/simple-postgres@gregnr/postgres-meta@halkeye/hubot-postgres-brain@heisian/knex@foodfresh/postgraphql@hyperjumptech/monika@hscloud/sequelize-dmdb@hoang_ng/directus-extension-dependent-fields@ff00ff/mammoth-cli@embracesql/postgres@golemio/cli@futureprimitive/ponder-core@getodk/slonik@infurnia/sequelize@insidelabs/sqltyper@infinitebrahmanuniverse/nolb-pg@lanrey/pg@leichtgewicht/postgraphql@lindapoggio/knex@lyxsus/postgraphile@lukeramsden/graphile-scheduler@makeen.io/run.pg@metis-data/prisma-interceptor@metis-data/slow-query-log@micburks/pg@mvtva/postgraphile
2.7.0

9 months ago

2.6.4

1 year ago

2.6.3

1 year ago

2.6.1

2 years ago

2.6.2

2 years ago

2.6.0

2 years ago

2.5.0

4 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

6 years ago

2.0.0

8 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago