simple-oracledb
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -356,3 +356,3 @@ ## Classes | ||
* _static_ | ||
* [.extend(pool)](#Pool.extend) | ||
* [.extend(pool, [poolAttributes])](#Pool.extend) | ||
@@ -411,3 +411,3 @@ <a name="new_Pool_new"></a> | ||
<a name="Pool.extend"></a> | ||
### Pool.extend(pool) | ||
### Pool.extend(pool, [poolAttributes]) | ||
Extends the provided oracledb pool instance. | ||
@@ -418,5 +418,8 @@ | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| pool | <code>object</code> | The oracledb pool instance | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| pool | <code>object</code> | | The oracledb pool instance | | ||
| [poolAttributes] | <code>object</code> | | The connection pool attributes object | | ||
| [poolAttributes.retryCount] | <code>number</code> | <code>10</code> | The max amount of retries to get a connection from the pool in case of any error | | ||
| [poolAttributes.retryInterval] | <code>number</code> | <code>250</code> | The interval in millies between get connection retry attempts | | ||
@@ -423,0 +426,0 @@ <a name="RecordReader"></a> |
'use strict'; | ||
var asyncLib = require('async'); | ||
var Connection = require('./connection'); | ||
@@ -50,3 +51,10 @@ | ||
Pool.prototype.getConnection = function (callback) { | ||
this.getConnectionOrg(Connection.wrapOnConnection(callback)); | ||
var self = this; | ||
asyncLib.retry({ | ||
times: Math.max(self.poolAttributes.retryCount || 10, 1), | ||
interval: self.poolAttributes.retryInterval || 250 | ||
}, function attemptGetConnection(asyncCallback) { | ||
self.getConnectionOrg(asyncCallback); | ||
}, Connection.wrapOnConnection(callback)); | ||
}; | ||
@@ -91,6 +99,10 @@ | ||
* @param {object} pool - The oracledb pool instance | ||
* @param {object} [poolAttributes] - The connection pool attributes object | ||
* @param {number} [poolAttributes.retryCount=10] - The max amount of retries to get a connection from the pool in case of any error | ||
* @param {number} [poolAttributes.retryInterval=250] - The interval in millies between get connection retry attempts | ||
*/ | ||
extend: function extend(pool) { | ||
extend: function extend(pool, poolAttributes) { | ||
if (pool && (!pool.simplified)) { | ||
pool.getConnectionOrg = pool.getConnection; | ||
pool.poolAttributes = poolAttributes || {}; | ||
@@ -97,0 +109,0 @@ var properties = Object.keys(Pool.prototype); |
@@ -108,2 +108,4 @@ 'use strict'; | ||
* @param {object} poolAttributes - The connection pool attributes object | ||
* @param {number} [poolAttributes.retryCount=10] - The max amount of retries to get a connection from the pool in case of any error | ||
* @param {number} [poolAttributes.retryInterval=250] - The interval in millies between get connection retry attempts | ||
* @param {AsyncCallback} callback - Invoked with an error or the oracle connection pool instance | ||
@@ -115,5 +117,10 @@ */ | ||
var callback = argumentsArray.pop(); | ||
var poolAttributes; | ||
if (argumentsArray && argumentsArray.length) { | ||
poolAttributes = argumentsArray[0]; | ||
} | ||
argumentsArray.push(function onPool(error, pool) { | ||
if ((!error) && pool) { | ||
Pool.extend(pool); | ||
Pool.extend(pool, poolAttributes); | ||
} | ||
@@ -120,0 +127,0 @@ |
{ | ||
"name": "simple-oracledb", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "Extend capabilities of oracledb with simplified API for quicker development.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -11,10 +11,14 @@ # simple-oracledb | ||
* [Usage](#usage) | ||
* [query](#usage-query) | ||
* [insert](#usage-insert) | ||
* [update](#usage-update) | ||
* [queryJSON](#usage-queryJSON) | ||
* [batchInsert](#usage-batchInsert) | ||
* [release](#usage-release) | ||
* [rollback](#usage-rollback) | ||
* [terminate](#usage-terminate) | ||
* [OracleDB](#usage-oracledb) | ||
* [createPool](#usage-createpool) | ||
* [Pool](#usage-pool) | ||
* [terminate](#usage-terminate) | ||
* [Connection](#usage-connection) | ||
* [query](#usage-query) | ||
* [insert](#usage-insert) | ||
* [update](#usage-update) | ||
* [queryJSON](#usage-queryJSON) | ||
* [batchInsert](#usage-batchInsert) | ||
* [release](#usage-release) | ||
* [rollback](#usage-rollback) | ||
* [Installation](#installation) | ||
@@ -98,2 +102,40 @@ * [Limitations](#limitations) | ||
<a name="usage-oracledb"></a> | ||
<a name="usage-createpool"></a> | ||
## 'oracledb.createPool(poolAttributes, callback)' | ||
This function modifies the existing oracledb.createPool function by enhancing the returned pool to support retry in the getConnection function.<br> | ||
The pool.getConnection will retry configurable amount of times with configurable interval between attempts to return a connection in the getConnection function.<br> | ||
In case all attempts fail, the getConnection callback will receive the error object of the last attempt. | ||
```js | ||
oracledb.createPool({ | ||
retryCount: 5, //The max amount of retries to get a connection from the pool in case of any error (default to 10 if not provided) | ||
retryInterval: 500, //The interval in millies between get connection retry attempts (defaults to 250 millies if not provided) | ||
//any other oracledb pool attributes | ||
}, function onPoolCreated(error, pool) { | ||
//continue flow | ||
}); | ||
``` | ||
<a name="usage-pool"></a> | ||
<a name="usage-terminate"></a> | ||
## 'pool.terminate([callback])' | ||
This function modifies the existing pool.terminate function by enabling the input | ||
callback to be an optional parameter.<br> | ||
Since there is no real way to release the pool that fails to be terminated, all that you can do in the callback | ||
is just log the error and continue.<br> | ||
Therefore this function allows you to ignore the need to pass a callback and makes it as an optional parameter. | ||
```js | ||
pool.terminate(); //no callback needed | ||
//still possible to call with a terminate callback function | ||
pool.terminate(function onTerminate(error) { | ||
if (error) { | ||
//now what? | ||
} | ||
}); | ||
``` | ||
<a name="usage-connection"></a> | ||
<a name="usage-query"></a> | ||
@@ -256,21 +298,2 @@ ## 'connection.query(sql, bindVariables, [options], callback)' | ||
``` | ||
<a name="usage-terminate"></a> | ||
## 'pool.terminate([callback])' | ||
This function modifies the existing pool.terminate function by enabling the input | ||
callback to be an optional parameter.<br> | ||
Since there is no real way to release the pool that fails to be terminated, all that you can do in the callback | ||
is just log the error and continue.<br> | ||
Therefore this function allows you to ignore the need to pass a callback and makes it as an optional parameter. | ||
```js | ||
pool.terminate(); //no callback needed | ||
//still possible to call with a terminate callback function | ||
pool.terminate(function onTerminate(error) { | ||
if (error) { | ||
//now what? | ||
} | ||
}); | ||
``` | ||
<br> | ||
@@ -305,2 +328,3 @@ **The rest of the API is the same as defined in the oracledb library: https://github.com/oracle/node-oracledb/blob/master/doc/api.md** | ||
| ----------- | ------- | ----------- | | ||
| 2015-11-17 | v0.0.17 | Added pool.getConnection automatic retry | | ||
| 2015-11-15 | v0.0.16 | Added connection.batchInsert and connection.rollback | | ||
@@ -307,0 +331,0 @@ | 2015-11-05 | v0.0.15 | Maintenance | |
@@ -22,3 +22,3 @@ 'use strict'; | ||
describe('getConnection tests', function () { | ||
it('getConnection simple', function () { | ||
it('getConnection simple', function (done) { | ||
var testPool = oracledb.createPool(); | ||
@@ -32,9 +32,13 @@ | ||
assert.isTrue(connection.simplified); | ||
done(); | ||
}) | ||
}); | ||
it('getConnection error', function () { | ||
it('getConnection error', function (done) { | ||
var testPool = oracledb.createPool(); | ||
Pool.extend(testPool); | ||
Pool.extend(testPool, { | ||
retryInterval: 5 | ||
}); | ||
@@ -45,4 +49,62 @@ testPool.throwError = true; | ||
assert.isUndefined(connection); | ||
done(); | ||
}) | ||
}); | ||
it('getConnection error with valid retry', function (done) { | ||
var testPool = oracledb.createPool(); | ||
var counter = 0; | ||
testPool.getConnection = function (callback) { | ||
counter++; | ||
if (counter < 2) { | ||
callback(new Error()); | ||
} else if (counter === 2) { | ||
callback(null, {}); | ||
} else { | ||
assert.fail(); | ||
} | ||
}; | ||
Pool.extend(testPool, { | ||
retryCount: 5 | ||
}); | ||
testPool.getConnection(function (error, connection) { | ||
assert.equal(counter, 2); | ||
assert.isNull(error); | ||
assert.isDefined(connection); | ||
assert.isTrue(connection.simplified); | ||
done(); | ||
}) | ||
}); | ||
it('getConnection error with error retry', function (done) { | ||
var testPool = oracledb.createPool(); | ||
var counter = 0; | ||
testPool.getConnection = function (callback) { | ||
counter++; | ||
if (counter > 10) { | ||
assert.fail(); | ||
} | ||
callback(new Error()); | ||
}; | ||
Pool.extend(testPool, { | ||
retryInterval: 5 | ||
}); | ||
testPool.getConnection(function (error) { | ||
assert.equal(counter, 10); | ||
assert.isDefined(error); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
@@ -49,0 +111,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
272339
5643
340