simple-oracledb
Advanced tools
Comparing version 0.0.34 to 0.0.35
@@ -87,9 +87,10 @@ ## Classes | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| sql | <code>string</code> | The SQL to execute | | ||
| [bindParams] | <code>object</code> | Optional bind parameters | | ||
| [options] | <code>object</code> | Optional execute options | | ||
| [options.streamResults] | <code>object</code> | True to enable to stream the results in bulks, each bulk will invoke the provided callback (last callback invocation will have empty results) | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | Invoked with an error or the query results object holding all data including LOBs | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| sql | <code>string</code> | | The SQL to execute | | ||
| [bindParams] | <code>object</code> | | Optional bind parameters | | ||
| [options] | <code>object</code> | | Optional execute options | | ||
| [options.streamResults] | <code>object</code> | | True to enable to stream the results in bulks, each bulk will invoke the provided callback (last callback invocation will have empty results) | | ||
| [options.bulkRowsAmount] | <code>number</code> | <code>100</code> | The amount of rows to fetch (for streaming, thats the max rows that the callback will get for each streaming invocation) | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | | Invoked with an error or the query results object holding all data including LOBs | | ||
@@ -110,3 +111,4 @@ **Example** | ||
connection.query('SELECT * FROM departments', { | ||
streamResults: true | ||
streamResults: true, | ||
bulkRowsAmount: 100 //The amount of rows to fetch (for streaming, thats the max rows that the callback will get for each streaming invocation) | ||
}, function onResults(error, results) { | ||
@@ -575,6 +577,6 @@ if (error) { | ||
* [new ResultSetReader()](#new_ResultSetReader_new) | ||
* [#readNextRows(columnNames, resultSet, callback)](#ResultSetReader+readNextRows) ℗ | ||
* [#readAllRows(columnNames, resultSet, callback, [jsRowsBuffer])](#ResultSetReader+readAllRows) ℗ | ||
* [#read(columnNames, resultSet, callback)](#ResultSetReader+read) | ||
* [#stream(columnNames, resultSet, callback)](#ResultSetReader+stream) | ||
* [#readNextRows(columnNames, resultSet, [options], callback)](#ResultSetReader+readNextRows) ℗ | ||
* [#readAllRows(columnNames, resultSet, options, callback, [jsRowsBuffer])](#ResultSetReader+readAllRows) ℗ | ||
* [#read(columnNames, resultSet, options, callback)](#ResultSetReader+read) | ||
* [#stream(columnNames, resultSet, options, callback)](#ResultSetReader+stream) | ||
@@ -586,3 +588,3 @@ <a name="new_ResultSetReader_new"></a> | ||
<a name="ResultSetReader+readNextRows"></a> | ||
### ResultSetReader#readNextRows(columnNames, resultSet, callback) ℗ | ||
### ResultSetReader#readNextRows(columnNames, resultSet, [options], callback) ℗ | ||
Reads the next rows data from the provided oracle ResultSet object. | ||
@@ -592,10 +594,12 @@ | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| columnNames | <code>Array</code> | Array of strings holding the column names of the results | | ||
| resultSet | <code>Array</code> | The oracle ResultSet object | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | called when the next rows have been read | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| columnNames | <code>Array</code> | | Array of strings holding the column names of the results | | ||
| resultSet | <code>Array</code> | | The oracle ResultSet object | | ||
| [options] | <code>object</code> | | Any options | | ||
| [options.bulkRowsAmount] | <code>number</code> | <code>100</code> | The amount of rows to fetch | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | | called when the next rows have been read | | ||
<a name="ResultSetReader+readAllRows"></a> | ||
### ResultSetReader#readAllRows(columnNames, resultSet, callback, [jsRowsBuffer]) ℗ | ||
### ResultSetReader#readAllRows(columnNames, resultSet, options, callback, [jsRowsBuffer]) ℗ | ||
Reads all data from the provided oracle ResultSet object into the provided buffer. | ||
@@ -609,2 +613,3 @@ | ||
| resultSet | <code>Array</code> | The oracle ResultSet object | | ||
| options | <code>object</code> | Any options | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | called when all rows are fully read or in case of an error | | ||
@@ -614,3 +619,3 @@ | [jsRowsBuffer] | <code>Array</code> | The result buffer, if not provided, the callback will be called for each bulk | | ||
<a name="ResultSetReader+read"></a> | ||
### ResultSetReader#read(columnNames, resultSet, callback) | ||
### ResultSetReader#read(columnNames, resultSet, options, callback) | ||
Reads all data from the provided oracle ResultSet object. | ||
@@ -624,6 +629,7 @@ | ||
| resultSet | <code>Array</code> | The oracle ResultSet object | | ||
| options | <code>object</code> | Any options | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | called when all rows are fully read or in case of an error | | ||
<a name="ResultSetReader+stream"></a> | ||
### ResultSetReader#stream(columnNames, resultSet, callback) | ||
### ResultSetReader#stream(columnNames, resultSet, options, callback) | ||
Streams all data from the provided oracle ResultSet object to the callback in bulks.<br> | ||
@@ -638,2 +644,3 @@ The last callback call will have an empty result. | ||
| resultSet | <code>Array</code> | The oracle ResultSet object | | ||
| options | <code>object</code> | Any options | | ||
| callback | <code>[AsyncCallback](#AsyncCallback)</code> | called for each read bulk of rows or in case of an error | | ||
@@ -640,0 +647,0 @@ |
@@ -58,2 +58,3 @@ 'use strict'; | ||
* @param {object} [options.streamResults] - True to enable to stream the results in bulks, each bulk will invoke the provided callback (last callback invocation will have empty results) | ||
* @param {number} [options.bulkRowsAmount=100] - The amount of rows to fetch (for streaming, thats the max rows that the callback will get for each streaming invocation) | ||
* @param {AsyncCallback} callback - Invoked with an error or the query results object holding all data including LOBs | ||
@@ -74,3 +75,4 @@ * @example | ||
* connection.query('SELECT * FROM departments', { | ||
* streamResults: true | ||
* streamResults: true, | ||
* bulkRowsAmount: 100 //The amount of rows to fetch (for streaming, thats the max rows that the callback will get for each streaming invocation) | ||
* }, function onResults(error, results) { | ||
@@ -109,5 +111,5 @@ * if (error) { | ||
if (streamResults) { | ||
resultSetReader.stream(results.metaData, results.resultSet, callback); | ||
resultSetReader.stream(results.metaData, results.resultSet, options, callback); | ||
} else { | ||
resultSetReader.read(results.metaData, results.resultSet, callback); | ||
resultSetReader.read(results.metaData, results.resultSet, options, callback); | ||
} | ||
@@ -114,0 +116,0 @@ } else { |
@@ -26,6 +26,17 @@ 'use strict'; | ||
* @param {Array} resultSet - The oracle ResultSet object | ||
* @param {object} [options] - Any options | ||
* @param {number} [options.bulkRowsAmount=100] - The amount of rows to fetch | ||
* @param {AsyncCallback} callback - called when the next rows have been read | ||
*/ | ||
ResultSetReader.prototype.readNextRows = function (columnNames, resultSet, callback) { | ||
resultSet.getRows(100, function onRows(error, rows) { | ||
ResultSetReader.prototype.readNextRows = function (columnNames, resultSet, options, callback) { | ||
var bulkRowsAmount = 100; | ||
if (arguments.length === 3) { | ||
callback = options; | ||
options = null; | ||
} else if (options) { | ||
bulkRowsAmount = options.bulkRowsAmount || bulkRowsAmount; | ||
} | ||
resultSet.getRows(bulkRowsAmount, function onRows(error, rows) { | ||
if (error) { | ||
@@ -49,9 +60,10 @@ callback(error); | ||
* @param {Array} resultSet - The oracle ResultSet object | ||
* @param {object} options - Any options | ||
* @param {AsyncCallback} callback - called when all rows are fully read or in case of an error | ||
* @param {Array} [jsRowsBuffer] - The result buffer, if not provided, the callback will be called for each bulk | ||
*/ | ||
ResultSetReader.prototype.readAllRows = function (columnNames, resultSet, callback, jsRowsBuffer) { | ||
ResultSetReader.prototype.readAllRows = function (columnNames, resultSet, options, callback, jsRowsBuffer) { | ||
var self = this; | ||
self.readNextRows(columnNames, resultSet, function onNextRows(error, jsRows) { | ||
self.readNextRows(columnNames, resultSet, options, function onNextRows(error, jsRows) { | ||
if (error) { | ||
@@ -67,3 +79,3 @@ callback(error); | ||
process.nextTick(function fetchNextRows() { | ||
self.readAllRows(columnNames, resultSet, callback, jsRowsBuffer); | ||
self.readAllRows(columnNames, resultSet, options, callback, jsRowsBuffer); | ||
}); | ||
@@ -85,6 +97,7 @@ } else { | ||
* @param {Array} resultSet - The oracle ResultSet object | ||
* @param {object} options - Any options | ||
* @param {AsyncCallback} callback - called when all rows are fully read or in case of an error | ||
*/ | ||
ResultSetReader.prototype.read = function (columnNames, resultSet, callback) { | ||
this.readAllRows(columnNames, resultSet, callback, []); | ||
ResultSetReader.prototype.read = function (columnNames, resultSet, options, callback) { | ||
this.readAllRows(columnNames, resultSet, options, callback, []); | ||
}; | ||
@@ -101,8 +114,9 @@ | ||
* @param {Array} resultSet - The oracle ResultSet object | ||
* @param {object} options - Any options | ||
* @param {AsyncCallback} callback - called for each read bulk of rows or in case of an error | ||
*/ | ||
ResultSetReader.prototype.stream = function (columnNames, resultSet, callback) { | ||
this.readAllRows(columnNames, resultSet, callback); | ||
ResultSetReader.prototype.stream = function (columnNames, resultSet, options, callback) { | ||
this.readAllRows(columnNames, resultSet, options, callback); | ||
}; | ||
module.exports = new ResultSetReader(); |
{ | ||
"name": "simple-oracledb", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"description": "Extend capabilities of oracledb with simplified API for quicker development.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -189,3 +189,4 @@ # simple-oracledb | ||
connection.query('SELECT * FROM departments', { | ||
streamResults: true | ||
streamResults: true, | ||
bulkRowsAmount: 100 //The amount of rows to fetch (for streaming, thats the max rows that the callback will get for each streaming invocation) | ||
}, function onResults(error, results) { | ||
@@ -372,2 +373,3 @@ if (error) { | ||
| ----------- | ------- | ----------- | | ||
| 2015-12-21 | v0.0.35 | New bulkRowsAmount option to manage query resultset behaviour | | ||
| 2015-12-21 | v0.0.34 | Added streaming of query results with new option streamResults=true | | ||
@@ -374,0 +376,0 @@ | 2015-12-17 | v0.0.33 | Maintenance | |
@@ -24,2 +24,112 @@ 'use strict'; | ||
describe('readNextRows tests', function () { | ||
it('array - all types without bulk size', function (done) { | ||
var date = new Date(); | ||
var lob1 = helper.createCLOB(); | ||
var lob2 = helper.createCLOB(); | ||
var dbData = [ | ||
[ | ||
['first row', 1, false, date] | ||
], | ||
[ | ||
[1, 'test', 50, lob1], | ||
['a', date, undefined, null] | ||
], | ||
[ | ||
[10, true, lob2, 100] | ||
] | ||
]; | ||
var dbEvents = [null, function () { | ||
lob1.emit('data', 'test1'); | ||
lob1.emit('data', '\ntest2'); | ||
lob1.emit('end'); | ||
}, function () { | ||
lob2.emit('data', '123'); | ||
lob2.emit('data', '456'); | ||
lob2.emit('end'); | ||
}]; | ||
ResultSetReader.readNextRows(columnNames, { | ||
getRows: function (number, callback) { | ||
assert.equal(number, 100); | ||
var events = dbEvents.shift(); | ||
if (events) { | ||
setTimeout(events, 10); | ||
} | ||
callback(null, dbData.shift()); | ||
} | ||
}, function (error, jsRows) { | ||
assert.isNull(error); | ||
assert.deepEqual([ | ||
{ | ||
COL1: 'first row', | ||
COL2: 1, | ||
COL3: false, | ||
COL4: date | ||
} | ||
], jsRows); | ||
done(); | ||
}); | ||
}); | ||
it('array - all types with bulk size', function (done) { | ||
var date = new Date(); | ||
var lob1 = helper.createCLOB(); | ||
var lob2 = helper.createCLOB(); | ||
var dbData = [ | ||
[ | ||
['first row', 1, false, date] | ||
], | ||
[ | ||
[1, 'test', 50, lob1], | ||
['a', date, undefined, null] | ||
], | ||
[ | ||
[10, true, lob2, 100] | ||
] | ||
]; | ||
var dbEvents = [null, function () { | ||
lob1.emit('data', 'test1'); | ||
lob1.emit('data', '\ntest2'); | ||
lob1.emit('end'); | ||
}, function () { | ||
lob2.emit('data', '123'); | ||
lob2.emit('data', '456'); | ||
lob2.emit('end'); | ||
}]; | ||
ResultSetReader.readNextRows(columnNames, { | ||
getRows: function (number, callback) { | ||
assert.equal(number, 5); | ||
var events = dbEvents.shift(); | ||
if (events) { | ||
setTimeout(events, 10); | ||
} | ||
callback(null, dbData.shift()); | ||
} | ||
}, { | ||
bulkRowsAmount: 5 | ||
}, function (error, jsRows) { | ||
assert.isNull(error); | ||
assert.deepEqual([ | ||
{ | ||
COL1: 'first row', | ||
COL2: 1, | ||
COL3: false, | ||
COL4: date | ||
} | ||
], jsRows); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('read tests', function () { | ||
@@ -32,3 +142,3 @@ it('empty', function (done) { | ||
} | ||
}, function (error, jsRows) { | ||
}, null, function (error, jsRows) { | ||
assert.isNull(error); | ||
@@ -79,3 +189,3 @@ assert.deepEqual([], jsRows); | ||
} | ||
}, function (error, jsRows) { | ||
}, null, function (error, jsRows) { | ||
assert.isNull(error); | ||
@@ -171,3 +281,3 @@ assert.deepEqual([ | ||
} | ||
}, function (error, jsRows) { | ||
}, null, function (error, jsRows) { | ||
assert.isNull(error); | ||
@@ -243,3 +353,3 @@ assert.deepEqual([ | ||
} | ||
}, function (error) { | ||
}, null, function (error) { | ||
assert.isDefined(error); | ||
@@ -310,3 +420,3 @@ assert.equal(error.message, 'lob2 error'); | ||
} | ||
}, function (error) { | ||
}, null, function (error) { | ||
assert.isDefined(error); | ||
@@ -326,3 +436,3 @@ assert.equal(error.message, 'lob2 error'); | ||
} | ||
}, function (error) { | ||
}, null, function (error) { | ||
assert.isDefined(error); | ||
@@ -343,3 +453,3 @@ assert.equal(error.message, 'getrows'); | ||
} | ||
}, function (error, jsRows) { | ||
}, null, function (error, jsRows) { | ||
assert.isNull(error); | ||
@@ -423,3 +533,3 @@ assert.deepEqual([], jsRows); | ||
} | ||
}, function (error, jsRows) { | ||
}, null, function (error, jsRows) { | ||
assert.isNull(error); | ||
@@ -527,3 +637,3 @@ assert.deepEqual(outputData.shift(), jsRows); | ||
} | ||
}, function (error, jsRows) { | ||
}, null, function (error, jsRows) { | ||
assert.isNull(error); | ||
@@ -579,3 +689,3 @@ assert.deepEqual(outputData.shift(), jsRows); | ||
} | ||
}, function (error) { | ||
}, null, function (error) { | ||
counter++; | ||
@@ -654,3 +764,3 @@ | ||
} | ||
}, function (error) { | ||
}, null, function (error) { | ||
counter++; | ||
@@ -676,3 +786,3 @@ | ||
} | ||
}, function (error) { | ||
}, null, function (error) { | ||
assert.isDefined(error); | ||
@@ -679,0 +789,0 @@ assert.equal(error.message, 'getrows'); |
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
313308
6730
392