- Notifications
You must be signed in to change notification settings - Fork5
SAP HANA Database Connection Pool for Node.js
License
ckyycc/hdb-pool
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Connection Pooling is fully supported by offical hana client, please useNode.js Connection Pooling instead
HANA Database Connection pool for Node.js, inspired by (and copied some ideas from):Generic Pool.
This module supportshana-client andnode-hdb.If both exist, thehana-client will be chosen.
- Install
- Getting started
- Creating a pool
- Getting a connection
- Returning a connection
- Destroying a connection
- Clearing the pool
- Receiving events from pool
- Getting status overview of pool
- Running tests
- License
npm install hdb-pool
This is an example how to use this module:
// import the moduleconstPool=require('hdb-pool');// HANA connection infoconstdbParams={hostName:'hana-server-name',port:'30015',userName:'user-name',password:'user-password'};// pool optionsconstoptions={min:2,max:15,};// create the poolconstpool=Pool.createPool(dbParams,options);// execute some sample sql via the poolpool.getConnection().then(conn=>{conn.exec('select current_timestamp from dummy',(err,rows)=>{//return the connection back to poolpool.release(client);if(err){// error handling}else{// handle the result: rows}});}).catch(err=>{// error handling});
The pool constructor takes two arguments:
dbParams
: a dictionary containing the HANA DB connection information.options
: a dictionary containing the configuration for thePool
constPool=require('hdb-pool');constpool=Pool.createPool(dbParams,options);
A dictionary with following properties:
hostName
: host name of HANA server.port
: port number.userName
: user name.password
: password.
Anoptional dictionary with the any of the following properties:
max
: maximum number of resources to create at any given time. (default=50)min
: minimum number of resources to keep in pool at any given time. (default=3)maxWaitingRequests
: maximum number of waiting requests allowed. (default=0, no limit)requestTimeout
: max milliseconds arequest
will wait for a resource before timing out. (default=5000)checkInterval
: how often to run resource timeout checks. (default=0, disabled)idleTimeout
: the time of a connection staying idle in the pool that eligible for eviction. (default=30000)debug
: a flag for emitting those debug message. (default=false, disabled)
pool.getConnection().then(conn=>{...}).catch(err=>{...});
Getting a HANAconnection
from the pool, thegetConnecction
does not have any argument.
It returns aPromise
. The promise will be resolved with aconnection
if the connection is available in the pool. And the promise will be rejected with an error if the pool is unable to give a connection(eg: timeout).
pool.release(connection).then(()=>{...}).catch(err=>{...});
Returning aconnection
to the pool, therelease
takes one required argument:
connection
: a 'borrowed' connection.
This function returns aPromise
. This promise will resolve once theconnection
is accepted by the pool, or reject if the pool is unable to accept theconnection
for any reason (e.gconnection
is not a resource that came from the pool). If you do not care the outcome it is safe to ignore this promise.
pool.destroy(connection).then(()=>{...}).catch(err=>{...});
Removing theconnection
from the pool and destroy theconnection
itself as well. The function takes one required argument:
connection
: a "borrowed" connection.
This function returns aPromise
. This promise will resolve once theconnection
is accepted by the pool, If you do not care the outcome it is safe to ignore this promise.
pool.clear().then(()=>{...}).catch(err=>{...});
This function clears thepool
, removing/destroying all the connections and all the pending requests from the pool.
Pool.eventEmitter.on('poolDebug',myEventHandler);Pool.eventEmitter.on('poolError',myEventHandlerError);Pool.eventEmitter.on('connectionCreateError',myEventHandlerCreateError);Pool.eventEmitter.on('connectionValidationError',myEventHandlerValidateError);Pool.eventEmitter.on('requestTimeout',myEventHandlerValidateError);
Pool supports 5 different types of events:
poolDebug
: debug information of the pool, needs to be enabled byoptions.debug first.poolError
: error information of the pool.connectionCreateError
: connection creation error.connectionValidationError
: connection validation error.requestTimeout
: request timeout.
constoverview=pool.getPoolStatusOverview();
This function will show current status of the pool.
npm installnpmtest
About
SAP HANA Database Connection Pool for Node.js