Skip to content

API StaticPool

Thiago Delgado Pinto edited this page Dec 13, 2017 · 4 revisions

The StaticPool is a Pool implementation where the pools for a given connection URL are static. That is two constructors with the same URL will still use the same pool of connections.

Syntax

new StaticPool( connection: string | ConnectionObject, poolSize: integer, driver?: DatabaseDriver )

Arguments

Parameter Type Description
connection string or ConnectionObject Defines the connection parameters for all connections in the pool.
poolSize integer Defines the number of connections in the pool.
driver DatabaseDriver An optional parameter. Used to pass in a specific driver class. If this is specified, the driver name is ignored in the connection argument.

Properties

Property Type Description
Available integer Returns the number of available connections in the pool.
InUse integer Returns the number of connection in use from the pool.
Count integer Returns the total number of connections n the pool

Methods

getConnection

Retrieves an available connection from the pool, or adds one if required.

Syntax

getConnection() => PooledConnection

Returns

Type Description
PooledConnection The next available connection from the pool.
If no connections are available, a new one is created.

close

Closes the pool and forces all connections in the pool to close;

Syntax

close() => Promise<boolean>

Returns

Type Description
Promise<boolean> A boolean promise that resolves when all the connections in the pool have been closed.