Initialization Options

Below is the complete list of Initialization Options for the library that can be passed during the library's initialization:

const initOptions = {/* options as documented below */};

const pgp = require('pg-promise')(initOptions);
Parameters:
Name Type Attributes Description
options object <optional>

Library Initialization Options.

Properties
Name Type Attributes Default Description
pgFormatting boolean <optional>
false

Redirects all query formatting to the pg driver.

By default (false), the library uses its own advanced query-formatting engine. If you pass in this option as true, query formatting will be done entirely by the pg driver, and you won't be able to use any of the feature-rich query formatting that this library implements.

This option is dynamic (can be set before or after initialization).

pgNative boolean <optional>
false

Use Native Bindings. Library pg-native must be included and installed independently, or else there will be an error thrown: Error = Failed to initialize Native Bindings.

This is a static option (can only be set prior to initialization).

promiseLib object | function <optional>
Promise

Overrides the default promise library (ES6 Promise).

example:

const Promise = require('bluebird');
const initOptions = {
    promiseLib: Promise
};
const pgp = require('pg-promise')(initOptions);

This is a static option (can only be set prior to initialization).

noLocking boolean <optional>
false

Prevents protocol locking.

By default, the library locks much of its protocol to read-only access, as a fool-proof mechanism. Specifically for the extend event this serves as a protection against overriding existing properties or trying to set them at the wrong time.

If this provision gets in the way of using a mock-up framework for your tests, you can force the library to deactivate most of the locks by setting noLocking = true within the options.

This option is dynamic (can be set before or after initialization).

capSQL boolean <optional>
false

Capitalizes any SQL generated by the library.

By default, all internal SQL within the library is generated using the low case. If, however, you want all SQL to be capitalized instead, set capSQL = true.

It is purely a cosmetic feature.

This option is dynamic (can be set before or after initialization).

noWarnings boolean <optional>
false

Disables all diagnostic warnings in the library (it is ill-advised).

This option is dynamic (can be set before or after initialization).

connect function <optional>

Global event connect handler.

This option is dynamic (can be set before or after initialization).

disconnect function <optional>

Global event disconnect handler.

This option is dynamic (can be set before or after initialization).

query function <optional>

Global event query handler.

This option is dynamic (can be set before or after initialization).

receive function <optional>

Global event receive handler.

task function <optional>

Global event task handler.

This option is dynamic (can be set before or after initialization).

transact function <optional>

Global event transact handler.

This option is dynamic (can be set before or after initialization).

error function <optional>

Global event error handler.

This option is dynamic (can be set before or after initialization).

extend function <optional>

Global event extend handler.

This option is dynamic (can be set before or after initialization).

Author:
  • Vitaly Tomilov
Source:
See:

Members

(inner, readonly) as :formatting

Namespace for all query-formatting functions.

Available as pgp.as, before and after initializing the library.

Type:
Source:
See:

(inner, readonly) end :function

Shuts down all connection pools currently allocated, so the process can terminate without delay. It is available as pgp.end, after initializing the library.

All Database objects created previously can no longer be used, throwing Error = Connection pool of the database object has been destroyed.

And if you want to shut down only a specific connection pool, you do so via the Database object that owns the pool: db.$pool.end() (see Database.$pool).

Type:
  • function
Source:

(inner, readonly) errors :errors

errors - namespace for all error types.

Available as pgp.errors, before and after initializing the library.

Type:
Source:

(inner, readonly) helpers :helpers

Namespace for all query-formatting helper functions.

Available as pgp.helpers, after initializing the library.

Type:
Source:
See:

(inner, readonly) minify :external:pg-minify

Instance of the pg-minify library used internally to minify SQL scripts.

Available as pgp.minify, before and after initializing the library.

Type:
Source:

(inner, readonly) ParameterizedQuery :ParameterizedQuery

ParameterizedQuery class.

Available as pgp.ParameterizedQuery, before and after initializing the library.

Type:
Source:

(inner, readonly) pg :external:PG

Instance of the pg library that's being used, depending on initialization option pgNative:

  • regular pg module instance, without option pgNative, or equal to false (default)
  • pg module instance with Native Bindings, if option pgNative was set.

Available as pgp.pg, after initializing the library.

Type:
Source:

(inner, readonly) PreparedStatement :PreparedStatement

PreparedStatement class.

Available as pgp.PreparedStatement, before and after initializing the library.

Type:
Source:

(inner, readonly) PromiseAdapter :PromiseAdapter

PromiseAdapter class.

Available as pgp.PromiseAdapter, before and after initializing the library.

Type:
Source:

(inner, readonly) QueryFile :QueryFile

QueryFile class.

Available as pgp.QueryFile, before and after initializing the library.

Type:
Source:

(inner, readonly) queryResult :queryResult

Query Result Mask enumerator.

Available as pgp.queryResult, before and after initializing the library.

Type:
Source:

(inner, readonly) spex :external:spex

Initialized instance of the spex module, used by the library within tasks and transactions.

Available as pgp.spex, after initializing the library.

Type:
Source:
See:

(inner, readonly) txMode :txMode

Transaction Mode namespace.

Available as pgp.txMode, before and after initializing the library.

Type:
Source:

(inner, readonly) utils :utils

utils - namespace for utility functions.

Available as pgp.utils, before and after initializing the library.

Type:
Source: