Skip to content

Commit

Permalink
fea: add support for pool.initAsync() API, PR #953, issue #952
Browse files Browse the repository at this point in the history
  • Loading branch information
bimalkjha committed Nov 15, 2023
1 parent 711ec48 commit ceafbb5
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 88 deletions.
34 changes: 31 additions & 3 deletions APIDocumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,8 @@ use Pool.open instead of [ibmdb.open](#1-openconnectionstring-options-callback).
3. [.close(callback)](#-3-closecallback)
4. [.closeSync()](#-4-closesync)
5. [.init(N, connStr)](#-5-initn-connstr)
6. [.setMaxPoolSize(N)](#-6-setmaxpoolsizen)
6. [.initAsync(N, connStr, callback)](#-6-initasyncn-connstr-callback)
7. [.setMaxPoolSize(N)](#-7-setmaxpoolsizen)
### <a name="openPoolApi"></a> 1) .open(connectionString, callback)
Expand Down Expand Up @@ -1519,7 +1520,7 @@ console.log("All connections in the pool are closed.");
### <a name="initPoolApi"></a> 5) .init(N, connStr)
Initialize `Pool` with N no of active connections using supplied connection string.
It is a synchronous API. We do not need an asynchronous version of this API.
It is a synchronous API.
* **N** - No of connections to be initialized.
* **connStr** - The connection string for your database
Expand All @@ -1535,7 +1536,34 @@ pool.open(connStr, function(err, db) { ...
```
Check [test-max-pool-size.js](https://github.com/ibmdb/node-ibm_db/blob/master/test/test-max-pool-size.js) for example.
### <a name="setMaxPoolSize"></a> 6) .setMaxPoolSize(N)
### <a name="initAsyncApi"></a> 6) .initAsync(N, connStr, callback)
Initialize `Pool` with N no of active connections using supplied connection string.
It is an asynchronous API.
* **N** - No of connections to be initialized.
* **connStr** - The connection string for your database or a JSON Object with connection information
* **callback** - `callback (err)`
```
pool.initAsync(5, connStr, function(err) {
if(err) {
console.log(err);
return false;
}
pool.open(connStr, function(err, db) { ... });
});

try {
await pool.initAsync(1, cn);
let conn = await pool.open(cn);
let data = await conn.query("select 1 from sysibm.sysdummy1");
console.log("data = ", data);
} catch(err) {console.log(err);}
```
Check [test-asyc-await.js](https://github.com/ibmdb/node-ibm_db/blob/master/test/test-asyc-await.js) for example.
### <a name="setMaxPoolSize"></a> 7) .setMaxPoolSize(N)
Number of maximum connection to database supported by current pool.
Expand Down
Loading

0 comments on commit ceafbb5

Please sign in to comment.