Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-connection-string-edge

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-connection-string-edge

Functions for dealing with a PostgresSQL connection string with edge patches

  • 2.6.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

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:

  • host - Postgres server hostname or, for UNIX domain 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
    • 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.

Keywords

FAQs

Package last updated on 09 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc