Skip to content

DbPoolPg

do- edited this page Jan 7, 2023 · 15 revisions

DbPoolPg is a doix ResourcePool of connections to a PostgreSQL database.

It is a thin wrapper over the native driver's connection pool.

It provides access to databases for business methods executed by Jobs by injecting there proxy variables. For example, normally, the main application's database is represented by the pool named "db", so each Job have the .db property visible to business methods as this.db, instance of DbClientPg.

Constructor

The class is designed to provide some Application's initialization parameters:

const {Application} = require ('doix')
const {DbPoolPg} = require ('doix-db-postgresql')

const app = new Application ({
  pools: {
    db: new DbPoolPg ({
      db: {host: '127.0.0.1', port: 5432},
//    logger: ConsoleLogger.DEFAULT,
//    eventLoggerClass: require ('MySpecialDbLogger'),
    })
  }
})

Options

Name Description
db options forwarded to the native constructor
logger A winston like Logger object. Unless mentioned, all output goes to containing Job's loggers.
eventLoggerClass An EventLogger descendant class to create for each new client instance. By default, DbEventLoggerPg is used.

Properties

Name Description
pool The pg.Pool instance used by this wrapper
logger Copy of the logger constructor option
eventLoggerClass Copy of the eventLoggerClass constructor option or DbEventLoggerPg by default
wrapper always DbClientPg

Methods

acquire ()

This mandatory method is implemented by calling the native connect ().

Clone this wiki locally