/utils/dbs
Database connection and query management module that creates connection pools for multiple databases based on xyzEnvironment variables prefixed with 'DBS_'.
The node-postgres package is required to create a new connection Pool for DBS connections.
- Source
Requires
- module:pg
- module:/utils/logger
- module:/utils/processEnv
Methods
(async, inner) clientQuery(pool, query, variablesopt, timeoutopt) → {Promise.<(Array|Error)>}
The clientQuery method creates a client connection from the provided Pool and executes a query on this pool.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pool | Pool | The node-postgres connection Pool for a Client connection. | |
query | string | SQL query to execute | |
variables | Array | <optional> | Parameters for the SQL query |
timeout | number | <optional> | Statement timeout in milliseconds |
- Source
Throws:
Database connection or query errors
- Type
- Error
Returns:
Query results or error object
- Type:
- Promise.<(Array|Error)>
(inner) sleep(ms) → {Promise.<void>}
Helper function to pause execution
Parameters:
Name | Type | Description |
---|---|---|
ms | number | Time to sleep in milliseconds |
- Source
Returns:
- Type:
- Promise.<void>