simple-oracledb
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -47,3 +47,3 @@ ## Classes | ||
* [#modifyParams(argumentsArray)](#Connection+modifyParams) ⇒ <code>object</code> ℗ | ||
* [#createCallback(callback, [output])](#Connection+createCallback) ⇒ <code>function</code> ℗ | ||
* [#createCallback(callback, commit, [output])](#Connection+createCallback) ⇒ <code>function</code> ℗ | ||
* _static_ | ||
@@ -109,2 +109,3 @@ * [.extend(connection)](#Connection.extend) | ||
| options | <code>object</code> | Any execute options | | ||
| [options.autoCommit] | <code>object</code> | If you wish to commit after the update, this property must be set to true in the options (oracledb.autoCommit is not checked) | | ||
| [options.lobMetaInfo] | <code>object</code> | For LOB support this object must hold a mapping between DB column name and bind variable name | | ||
@@ -120,2 +121,3 @@ | callback | <code>[AsyncCallback](#AsyncCallback)</code> | Invoked with an error or the insert results (if LOBs are provided, the callback will be triggered after they have been fully written to the DB) | | ||
}, { | ||
autoCommit: true, //must be set to true in options to support auto commit after update is done, otherwise the auto commit will be false (oracledb.autoCommit is not checked) | ||
lobMetaInfo: { //if LOBs are provided, this data structure must be provided in the options object and the bind variables parameter must be an object (not array) | ||
@@ -143,2 +145,3 @@ clob_column1: 'clobText1', //map oracle column name to bind variable name | ||
| options | <code>object</code> | Any execute options | | ||
| [options.autoCommit] | <code>object</code> | If you wish to commit after the update, this property must be set to true in the options (oracledb.autoCommit is not checked) | | ||
| [options.lobMetaInfo] | <code>object</code> | For LOB support this object must hold a mapping between DB column name and bind variable name | | ||
@@ -155,2 +158,3 @@ | callback | <code>[AsyncCallback](#AsyncCallback)</code> | Invoked with an error or the update results (if LOBs are provided, the callback will be triggered after they have been fully written to the DB) | | ||
}, { | ||
autoCommit: true, //must be set to true in options to support auto commit after update is done, otherwise the auto commit will be false (oracledb.autoCommit is not checked) | ||
lobMetaInfo: { //if LOBs are provided, this data structure must be provided in the options object and the bind variables parameter must be an object (not array) | ||
@@ -203,3 +207,3 @@ clob_column1: 'clobText1', //map oracle column name to bind variable name | ||
<a name="Connection+createCallback"></a> | ||
### Connection#createCallback(callback, [output]) ⇒ <code>function</code> ℗ | ||
### Connection#createCallback(callback, commit, [output]) ⇒ <code>function</code> ℗ | ||
Internal function used to wrap the original callback. | ||
@@ -213,2 +217,3 @@ | ||
| callback | <code>function</code> | The callback function to invoke | | ||
| commit | <code>boolean</code> | True to run commit | | ||
| [output] | <code>object</code> | Optional output to pass to the callback | | ||
@@ -215,0 +220,0 @@ |
@@ -100,2 +100,3 @@ 'use strict'; | ||
* @param {object} options - Any execute options | ||
* @param {object} [options.autoCommit] - If you wish to commit after the update, this property must be set to true in the options (oracledb.autoCommit is not checked) | ||
* @param {object} [options.lobMetaInfo] - For LOB support this object must hold a mapping between DB column name and bind variable name | ||
@@ -110,2 +111,3 @@ * @param {AsyncCallback} callback - Invoked with an error or the insert results (if LOBs are provided, the callback will be triggered after they have been fully written to the DB) | ||
* }, { | ||
* autoCommit: true, //must be set to true in options to support auto commit after update is done, otherwise the auto commit will be false (oracledb.autoCommit is not checked) | ||
* lobMetaInfo: { //if LOBs are provided, this data structure must be provided in the options object and the bind variables parameter must be an object (not array) | ||
@@ -128,6 +130,7 @@ * clob_column1: 'clobText1', //map oracle column name to bind variable name | ||
var lobData = lobInfo.lobData; | ||
var autoCommit = lobInfo.autoCommit; | ||
var callback = argumentsArray.pop(); | ||
argumentsArray.push(function onExecute(error, results) { | ||
var wrapper = self.createCallback(callback, results); | ||
var wrapper = self.createCallback(callback, autoCommit, results); | ||
@@ -158,2 +161,3 @@ if (error || (!results)) { | ||
* @param {object} options - Any execute options | ||
* @param {object} [options.autoCommit] - If you wish to commit after the update, this property must be set to true in the options (oracledb.autoCommit is not checked) | ||
* @param {object} [options.lobMetaInfo] - For LOB support this object must hold a mapping between DB column name and bind variable name | ||
@@ -169,2 +173,3 @@ * @param {AsyncCallback} callback - Invoked with an error or the update results (if LOBs are provided, the callback will be triggered after they have been fully written to the DB) | ||
* }, { | ||
* autoCommit: true, //must be set to true in options to support auto commit after update is done, otherwise the auto commit will be false (oracledb.autoCommit is not checked) | ||
* lobMetaInfo: { //if LOBs are provided, this data structure must be provided in the options object and the bind variables parameter must be an object (not array) | ||
@@ -187,6 +192,7 @@ * clob_column1: 'clobText1', //map oracle column name to bind variable name | ||
var lobData = lobInfo.lobData; | ||
var autoCommit = lobInfo.autoCommit; | ||
var callback = argumentsArray.pop(); | ||
argumentsArray.push(function onExecute(error, results) { | ||
var wrapper = self.createCallback(callback, results); | ||
var wrapper = self.createCallback(callback, autoCommit, results); | ||
@@ -198,3 +204,3 @@ if (error || (!results)) { | ||
} else { | ||
wrapper(); | ||
wrapper(error); | ||
} | ||
@@ -250,2 +256,3 @@ }); | ||
var lobData; | ||
var autoCommit; | ||
if ((argumentsArray.length === 4) && argumentsArray[2] && argumentsArray[2].lobMetaInfo) { | ||
@@ -258,2 +265,3 @@ lobMetaInfo = argumentsArray[2].lobMetaInfo; | ||
if (lobColumns && lobColumns.length) { | ||
autoCommit = argumentsArray[2].autoCommit; | ||
argumentsArray[2].autoCommit = false; //must disable auto commit to support LOBs | ||
@@ -315,3 +323,4 @@ | ||
lobColumns: lobColumns, | ||
lobData: lobData | ||
lobData: lobData, | ||
autoCommit: autoCommit | ||
}; | ||
@@ -327,9 +336,20 @@ }; | ||
* @param {function} callback - The callback function to invoke | ||
* @param {boolean} commit - True to run commit | ||
* @param {object} [output] - Optional output to pass to the callback | ||
* @returns {function} A wrapper callback | ||
*/ | ||
Connection.prototype.createCallback = function (callback, output) { | ||
Connection.prototype.createCallback = function (callback, commit, output) { | ||
var self = this; | ||
return function onCallback(error) { | ||
if (error) { | ||
callback(error); | ||
} else if (commit) { | ||
self.commit(function onCommit(commitError) { | ||
if (commitError) { | ||
callback(commitError); | ||
} else { | ||
callback(null, output); | ||
} | ||
}); | ||
} else { | ||
@@ -336,0 +356,0 @@ callback(null, output); |
{ | ||
"name": "simple-oracledb", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Extend capabilities of oracledb with simplified API for quicker development.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -126,2 +126,3 @@ # simple-oracledb | ||
}, { | ||
autoCommit: true, //must be set to true in options to support auto commit after update is done, otherwise the auto commit will be false (oracledb.autoCommit is not checked) | ||
lobMetaInfo: { //if LOBs are provided, this data structure must be provided in the options object and the bind variables parameter must be an object (not array) | ||
@@ -150,2 +151,3 @@ clob_column1: 'clobText1', //map oracle column name to bind variable name | ||
}, { | ||
autoCommit: true, //must be set to true in options to support auto commit after update is done, otherwise the auto commit will be false (oracledb.autoCommit is not checked) | ||
lobMetaInfo: { //if LOBs are provided, this data structure must be provided in the options object and the bind variables parameter must be an object (not array) | ||
@@ -224,3 +226,3 @@ clob_column1: 'clobText1', //map oracle column name to bind variable name | ||
| ----------- | ------- | ----------- | | ||
| 2015-10-19 | v0.0.8 | autoCommit=false when doing INSERT/UPDATE with LOBs | | ||
| 2015-10-19 | v0.0.9 | autoCommit support when doing INSERT/UPDATE with LOBs | | ||
| 2015-10-19 | v0.0.7 | Added pool.terminate support | | ||
@@ -227,0 +229,0 @@ | 2015-10-19 | v0.0.6 | Maintenance | |
@@ -369,2 +369,3 @@ 'use strict'; | ||
}, { | ||
autoCommit: true, | ||
lobMetaInfo: { | ||
@@ -523,2 +524,3 @@ LOB1: 'clob1', | ||
}, { | ||
autoCommit: true, | ||
lobMetaInfo: { | ||
@@ -525,0 +527,0 @@ LOB1: 'clob1', |
@@ -326,2 +326,8 @@ 'use strict'; | ||
var commitCalled = false; | ||
connection.commit = function (callback) { | ||
commitCalled = true; | ||
callback(); | ||
}; | ||
var lobsWritten = 0; | ||
@@ -386,2 +392,3 @@ connection.execute = function (sql, bindVars, options, callback) { | ||
}, { | ||
autoCommit: true, | ||
lobMetaInfo: { | ||
@@ -396,2 +403,3 @@ c1: 'lob1', | ||
assert.equal(lobsWritten, 3); | ||
assert.isTrue(commitCalled); | ||
@@ -527,2 +535,84 @@ done(); | ||
}); | ||
it('error on commit', function (done) { | ||
var connection = {}; | ||
Connection.extend(connection); | ||
connection.commit = function (callback) { | ||
callback(new Error('commit error')); | ||
}; | ||
var lobsWritten = 0; | ||
connection.execute = function (sql, bindVars, options, callback) { | ||
assert.equal(sql, 'INSERT INTO mylobs (id, c1, c2, b) VALUES (:id, EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB()) RETURNING c1, c2, b INTO :lob1, :lob2, :lob3'); | ||
assert.deepEqual(bindVars, { | ||
id: 1, | ||
lob1: { | ||
type: constants.clobType, | ||
dir: constants.bindOut | ||
}, | ||
lob2: { | ||
type: constants.clobType, | ||
dir: constants.bindOut | ||
}, | ||
lob3: { | ||
type: constants.blobType, | ||
dir: constants.bindOut | ||
} | ||
}); | ||
assert.deepEqual(options, { | ||
autoCommit: false, | ||
lobMetaInfo: { | ||
c1: 'lob1', | ||
c2: 'lob2', | ||
b: 'lob3' | ||
} | ||
}); | ||
var lob1 = helper.createCLOB(); | ||
lob1.testData = 'clob text'; | ||
lob1.once('end', function () { | ||
lobsWritten++; | ||
}); | ||
var lob2 = helper.createCLOB(); | ||
lob2.testData = 'second clob text'; | ||
lob2.once('end', function () { | ||
lobsWritten++; | ||
}); | ||
var lob3 = helper.createBLOB(); | ||
lob3.testData = 'binary data'; | ||
lob3.once('end', function () { | ||
lobsWritten++; | ||
}); | ||
callback(null, { | ||
rowsAffected: 1, | ||
outBinds: { | ||
lob1: [lob1], | ||
lob2: [lob2], | ||
lob3: [lob3] | ||
} | ||
}); | ||
}; | ||
connection.insert('INSERT INTO mylobs (id, c1, c2, b) VALUES (:id, EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB())', { | ||
id: 1, | ||
lob1: 'clob text', | ||
lob2: 'second clob text', | ||
lob3: new Buffer('binary data') | ||
}, { | ||
autoCommit: true, | ||
lobMetaInfo: { | ||
c1: 'lob1', | ||
c2: 'lob2', | ||
b: 'lob3' | ||
} | ||
}, function (error) { | ||
assert.isDefined(error); | ||
assert.equal(error.message, 'commit error'); | ||
assert.equal(lobsWritten, 3); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -529,0 +619,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
211856
4372
235