DbPool

DbPool

new DbPool(options, defaults)

Description:
  • Create a new database pool with default methods and properties

Parameters:
Name Type Description
options object

an object with default pool properties, see Pool

Properties
Name Type Description
type string

pool type, this is the db driver name

pool string

actual pool name, overrides defaults.name because it is the driver module with generic name

min int

min number of open database connections

max int

max number of open database connections, all attempts to run more will result in clients waiting for the next available db connection, if set to 0 no pooling will be enabled and will result in the unlimited connections, this is default for DynamoDB

max_queue int

how many db requests can be in the waiting queue, above that all requests will be denied instead of putting in the waiting queue

defaults object

an object with default pool methods for init and shutdown and other properties

The db methods cover most use cases but in case native driver needs to be used this is how to get the client and use it with its native API, it is required to call pool.release at the end to return the connection back to the connection pool.

Example
var pool = db.getPool("pg");
pool.use((err, client) => {
   client.query("SELECT * from users", (err, rows) => {
      pool.release(client);
   });
});

// Or async version

const { client } = await pool.ause((err);
const { err, rows, info } = await client.aquery("SELECT * from users");
pool.release(client);