$ npm install pg-promise
Loading and initializing the library with Initialization Options:
const initOptions = {/* initialization options */};
const pgp = require('pg-promise')(initOptions);
− or without Initialization Options:
const pgp = require('pg-promise')();
Create your Database object from the connection as pgp(connection, [dc])
:
const db = pgp(connection);
- The
connection
parameter is either a Configuration Object or a Connection String. dc
= Database Context - optional parameter (see Database constructor).
Object db
represents the Database protocol with lazy connection, i.e. only the actual query methods acquire
and release the connection automatically. Therefore you should create only one global/shared db
object per connection details.
It is best to initialize the library and create Database in its own module, see Where should I initialize pg-promise.
Learn by Example is the best quick-start tutorial. For everything else see the WiKi pages.
- The library's Main Page
- TypeScript 3.x declarations
- The library's WiKi Pages
- Popular questions on StackOverflow
- Database - database-level methods and properties
- Task - extends Database with task-level methods and properties
- QueryFile - type for working with external SQL files
- PreparedStatement - type for working with Prepared Statements
- ParameterizedQuery - type for working with Parameterized Queries
- TransactionMode - transaction configuration type
- PromiseAdapter - adapter for using non-standard promise libraries
- formatting - the library's query formatting engine
- ctf - ES6 symbols used by Custom Type Formatting
- helpers - for automatic query generation
- utils - simplifies the use of external SQL files
- errors - custom error types supported by the library
- txMode - types for configuring a transaction