simple-oracledb
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -376,3 +376,6 @@ ## Classes | ||
Wraps the original oracledb getConnection in order to provide an extended connection object.<br> | ||
See https://github.com/oracle/node-oracledb/blob/master/doc/api.md#getconnectionpool for more details. | ||
In addition, this function will attempt to fetch a connection from the pool and in case of any error will reattempt for a configurable amount of times.<br> | ||
It will also ensure the provided connection is valid by running a test SQL and if validation fails, it will fetch another connection (continue to reattempt).<br> | ||
See https://github.com/oracle/node-oracledb/blob/master/doc/api.md#getconnectionpool for official API details.<br> | ||
See https://github.com/sagiegurari/simple-oracledb/blob/master/docs/api.md#SimpleOracleDB.oracle.createPool for extended createPool API details.<br> | ||
@@ -423,2 +426,4 @@ **Access:** public | ||
| [poolAttributes.retryInterval] | <code>number</code> | <code>250</code> | The interval in millies between get connection retry attempts | | ||
| [poolAttributes.runValidationSQL] | <code>boolean</code> | <code>true</code> | True to ensure the connection returned is valid by running a test validation SQL | | ||
| [poolAttributes.validationSQL] | <code>string</code> | <code>"SELECT 1 FROM DUAL"</code> | The test SQL to invoke before returning a connection to validate the connection is open | | ||
@@ -631,2 +636,5 @@ <a name="RecordReader"></a> | ||
* [#extend(connection)](#SimpleOracleDB+extend) | ||
* _static_ | ||
* [.oracle.getConnection(connectionAttributes, callback)](#SimpleOracleDB.oracle.getConnection) | ||
* [.oracle.createPool(poolAttributes, callback)](#SimpleOracleDB.oracle.createPool) | ||
@@ -671,2 +679,30 @@ <a name="new_SimpleOracleDB_new"></a> | ||
<a name="SimpleOracleDB.oracle.getConnection"></a> | ||
### SimpleOracleDB.oracle.getConnection(connectionAttributes, callback) | ||
Wraps the original oracledb getConnection in order to provide an extended connection object. | ||
**Kind**: static method of <code>[SimpleOracleDB](#SimpleOracleDB)</code> | ||
**Access:** public | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| connectionAttributes | <code>object</code> | The connection attributes object | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | Invoked with an error or the oracle connection instance | | ||
<a name="SimpleOracleDB.oracle.createPool"></a> | ||
### SimpleOracleDB.oracle.createPool(poolAttributes, callback) | ||
Wraps the original oracledb createPool in order to provide an extended pool object. | ||
**Kind**: static method of <code>[SimpleOracleDB](#SimpleOracleDB)</code> | ||
**Access:** public | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| 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 | | ||
| [poolAttributes.runValidationSQL] | <code>boolean</code> | <code>true</code> | True to ensure the connection returned is valid by running a test validation SQL | | ||
| [poolAttributes.validationSQL] | <code>string</code> | <code>"SELECT 1 FROM DUAL"</code> | The test SQL to invoke before returning a connection to validate the connection is open | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | | Invoked with an error or the oracle connection pool instance | | ||
<a name="Stream"></a> | ||
@@ -673,0 +709,0 @@ ## Stream |
@@ -43,3 +43,6 @@ 'use strict'; | ||
* Wraps the original oracledb getConnection in order to provide an extended connection object.<br> | ||
* See https://github.com/oracle/node-oracledb/blob/master/doc/api.md#getconnectionpool for more details. | ||
* In addition, this function will attempt to fetch a connection from the pool and in case of any error will reattempt for a configurable amount of times.<br> | ||
* It will also ensure the provided connection is valid by running a test SQL and if validation fails, it will fetch another connection (continue to reattempt).<br> | ||
* See https://github.com/oracle/node-oracledb/blob/master/doc/api.md#getconnectionpool for official API details.<br> | ||
* See https://github.com/sagiegurari/simple-oracledb/blob/master/docs/api.md#SimpleOracleDB.oracle.createPool for extended createPool API details.<br> | ||
* | ||
@@ -55,6 +58,22 @@ * @function | ||
asyncLib.retry({ | ||
times: Math.max(self.poolAttributes.retryCount || 10, 1), | ||
interval: self.poolAttributes.retryInterval || 250 | ||
times: self.poolAttributes.retryCount, | ||
interval: self.poolAttributes.retryInterval | ||
}, function attemptGetConnection(asyncCallback) { | ||
self.getConnectionOrg(asyncCallback); | ||
self.getConnectionOrg(function onConnection(error, connection) { | ||
if (error) { | ||
asyncCallback(error); | ||
} else if (self.poolAttributes.runValidationSQL && self.poolAttributes.validationSQL) { | ||
connection.execute(self.poolAttributes.validationSQL, function onExecuteDone(testError) { | ||
if (testError) { | ||
connection.release(function onConnectionRelease() { | ||
asyncCallback(testError); | ||
}); | ||
} else { | ||
asyncCallback(error, connection); | ||
} | ||
}); | ||
} else { | ||
asyncCallback(error, connection); | ||
} | ||
}); | ||
}, Connection.wrapOnConnection(callback)); | ||
@@ -103,2 +122,4 @@ }; | ||
* @param {number} [poolAttributes.retryInterval=250] - The interval in millies between get connection retry attempts | ||
* @param {boolean} [poolAttributes.runValidationSQL=true] - True to ensure the connection returned is valid by running a test validation SQL | ||
* @param {string} [poolAttributes.validationSQL=SELECT 1 FROM DUAL] - The test SQL to invoke before returning a connection to validate the connection is open | ||
*/ | ||
@@ -110,2 +131,10 @@ extend: function extend(pool, poolAttributes) { | ||
//set defaults | ||
pool.poolAttributes.retryCount = Math.max(pool.poolAttributes.retryCount || 10, 1); | ||
pool.poolAttributes.retryInterval = pool.poolAttributes.retryInterval || 250; | ||
if (pool.poolAttributes.runValidationSQL === undefined) { | ||
pool.poolAttributes.runValidationSQL = true; | ||
} | ||
pool.poolAttributes.validationSQL = pool.poolAttributes.validationSQL || 'SELECT 1 FROM DUAL'; | ||
var properties = Object.keys(Pool.prototype); | ||
@@ -112,0 +141,0 @@ |
@@ -85,3 +85,3 @@ 'use strict'; | ||
* @function | ||
* @memberof! oracledb | ||
* @memberof! SimpleOracleDB | ||
* @public | ||
@@ -106,3 +106,3 @@ * @param {object} connectionAttributes - The connection attributes object | ||
* @function | ||
* @memberof! oracledb | ||
* @memberof! SimpleOracleDB | ||
* @public | ||
@@ -112,2 +112,4 @@ * @param {object} poolAttributes - The connection pool attributes object | ||
* @param {number} [poolAttributes.retryInterval=250] - The interval in millies between get connection retry attempts | ||
* @param {boolean} [poolAttributes.runValidationSQL=true] - True to ensure the connection returned is valid by running a test validation SQL | ||
* @param {string} [poolAttributes.validationSQL=SELECT 1 FROM DUAL] - The test SQL to invoke before returning a connection to validate the connection is open | ||
* @param {AsyncCallback} callback - Invoked with an error or the oracle connection pool instance | ||
@@ -114,0 +116,0 @@ */ |
{ | ||
"name": "simple-oracledb", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"description": "Extend capabilities of oracledb with simplified API for quicker development.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -14,2 +14,3 @@ # simple-oracledb | ||
* [Pool](#usage-pool) | ||
* [getConnection](#usage-getconnection) | ||
* [terminate](#usage-terminate) | ||
@@ -113,2 +114,4 @@ * [Connection](#usage-connection) | ||
retryInterval: 500, //The interval in millies between get connection retry attempts (defaults to 250 millies if not provided) | ||
runValidationSQL: true, //True to ensure the connection returned is valid by running a test validation SQL (defaults to true) | ||
validationSQL: 'SELECT 1 FROM DUAL', The test SQL to invoke before returning a connection to validate the connection is open (defaults to 'SELECT 1 FROM DUAL') | ||
//any other oracledb pool attributes | ||
@@ -121,2 +124,23 @@ }, function onPoolCreated(error, pool) { | ||
<a name="usage-pool"></a> | ||
<a name="usage-getconnection"></a> | ||
## 'pool.getConnection(callback)' | ||
This function will attempt to fetch a connection from the pool and in case of any error will reattempt for a configurable amount of times.<br> | ||
It will also ensure the provided connection is valid by running a test SQL and if validation fails, it will fetch another connection (continue to reattempt).<br> | ||
See https://github.com/oracle/node-oracledb/blob/master/doc/api.md#getconnectionpool for official API details.<br> | ||
See https://github.com/sagiegurari/simple-oracledb/blob/master/docs/api.md#SimpleOracleDB.oracle.createPool for extended createPool API details. | ||
```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) | ||
runValidationSQL: true, //True to ensure the connection returned is valid by running a test validation SQL (defaults to true) | ||
validationSQL: 'SELECT 1 FROM DUAL', The test SQL to invoke before returning a connection to validate the connection is open (defaults to 'SELECT 1 FROM DUAL') | ||
//any other oracledb pool attributes | ||
}, function onPoolCreated(error, pool) { | ||
pool.getConnection(function onConnection(poolError, connection) { | ||
//continue flow (connection, if provided, has been tested to ensure it is valid) | ||
}); | ||
}); | ||
``` | ||
<a name="usage-terminate"></a> | ||
@@ -328,2 +352,3 @@ ## 'pool.terminate([callback])' | ||
| ----------- | ------- | ----------- | | ||
| 2015-12-08 | v0.0.24 | Added pool.getConnection connection validation via running SQL test command | | ||
| 2015-11-30 | v0.0.23 | Maintenance | | ||
@@ -330,0 +355,0 @@ | 2015-11-17 | v0.0.17 | Added pool.getConnection automatic retry | |
@@ -16,5 +16,15 @@ 'use strict'; | ||
TestConnection.prototype.execute = function () { | ||
arguments[arguments.length - 1](); | ||
var callback = arguments[arguments.length - 1]; | ||
if (this.throwError) { | ||
callback(new Error()); | ||
} else { | ||
callback(null, {}); | ||
} | ||
}; | ||
TestConnection.prototype.release = function (callback) { | ||
callback(); | ||
}; | ||
TestPool.prototype.getConnection = function (callback) { | ||
@@ -21,0 +31,0 @@ if (this.throwError) { |
@@ -69,3 +69,4 @@ 'use strict'; | ||
Pool.extend(testPool, { | ||
retryCount: 5 | ||
retryCount: 5, | ||
runValidationSQL: false | ||
}); | ||
@@ -90,3 +91,3 @@ | ||
if (counter > 10) { | ||
if (counter > 5) { | ||
assert.fail(); | ||
@@ -99,7 +100,8 @@ } | ||
Pool.extend(testPool, { | ||
retryInterval: 5 | ||
retryInterval: 5, | ||
retryCount: 5 | ||
}); | ||
testPool.getConnection(function (error) { | ||
assert.equal(counter, 10); | ||
assert.equal(counter, 5); | ||
assert.isDefined(error); | ||
@@ -110,2 +112,61 @@ | ||
}); | ||
it('getConnection sql error', function (done) { | ||
var testPool = oracledb.createPool(); | ||
var orgGetConnection = testPool.getConnection; | ||
testPool.getConnection = function (callback) { | ||
orgGetConnection.call(testPool, function (connError, connection) { | ||
connection.throwError = true; | ||
callback(null, connection); | ||
}); | ||
}; | ||
Pool.extend(testPool, { | ||
retryInterval: 5 | ||
}); | ||
testPool.getConnection(function (error, connection) { | ||
assert.isDefined(error); | ||
assert.isUndefined(connection); | ||
done(); | ||
}) | ||
}); | ||
it('getConnection sql error with valid retry', function (done) { | ||
var testPool = oracledb.createPool(); | ||
var orgGetConnection = testPool.getConnection; | ||
var counter = 0; | ||
testPool.getConnection = function (callback) { | ||
counter++; | ||
orgGetConnection.call(testPool, function (connError, connection) { | ||
connection.throwError = true; | ||
if (counter > 5) { | ||
assert.fail(); | ||
} else if (counter === 4) { | ||
connection.throwError = false; | ||
} | ||
callback(null, connection); | ||
}); | ||
}; | ||
Pool.extend(testPool, { | ||
retryInterval: 5 | ||
}); | ||
testPool.getConnection(function (error, connection) { | ||
assert.equal(counter, 4); | ||
assert.isNull(error); | ||
assert.isDefined(connection); | ||
assert.isTrue(connection.simplified); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
@@ -112,0 +173,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
281864
5724
366