Skip to content

Commit 2a05991

Browse files
committed
QueryStream updates: new destroy() method, simplified fetch logic, and various other fixes
1 parent d3fae22 commit 2a05991

File tree

7 files changed

+396
-178
lines changed

7 files changed

+396
-178
lines changed

doc/api.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ limitations under the License.
231231
21. [Async/Await and node-oracledb](#asyncawaitoverview)
232232
22. [Tracing SQL and PL/SQL Statements](#tracingsql)
233233
23. [Migrating from node-oracledb 1.13 to node-oracledb 2.0](#migratev1v2)
234+
24. [Migrating from node-oracledb 2.0 to node-oracledb 2.1](#migratev20v21)
234235

235236
## <a name="intro"></a> 1. Introduction
236237

@@ -3783,7 +3784,7 @@ function fetchRowsFromRS(connection, resultSet, numRows)
37833784
37843785
#### <a name="streamingresults"></a> 9.1.3 Query Streaming
37853786
3786-
Streaming query results allows data to be piped to other streams, for
3787+
Streaming of query results allows data to be piped to other streams, for
37873788
example when dealing with HTTP responses.
37883789
37893790
Use [`connection.queryStream()`](#querystream) to create a stream from
@@ -3797,27 +3798,21 @@ With streaming, each row is returned as a `data` event. Query
37973798
metadata is available via a `metadata` event. The `end` event
37983799
indicates the end of the query results.
37993800
3801+
Query results should be fetched to completion to avoid resource leaks,
3802+
or (from Node.js 8 onwards) the Stream [`destroy()`][92] method can be
3803+
used to terminate a stream early. For older Node.js versions use a
3804+
[ResultSet with callbacks](#resultsethandling) if you need to stop a
3805+
query before retrieving all data. Note the previous, experimental
3806+
`_close()` method no longer emits a 'close' event.
3807+
38003808
The connection must remain open until the stream is completely read.
38013809
38023810
The query stream implementation is a wrapper over the [ResultSet
3803-
Class](#resultsetclass). In particular, calls to
3804-
[getRows()](#getrows) are made internally to fetch each successive
3805-
subset of data, each row of which will generate a `data` event. The
3806-
number of rows fetched from the database by each `getRows()` call is
3807-
set to the value of [`oracledb.fetchArraySize`](#propdbfetcharraysize)
3808-
or the option [`fetchArraySize`](#propexecfetcharraysize). This value
3809-
does not alter the number of rows returned by the stream since
3810-
`getRows()` will be called each time more rows are needed. However
3811-
the value can be used to tune performance.
3812-
3813-
Query results must be fetched to completion to avoid resource leaks.
3814-
The ResultSet `close()` call for streaming query results will be
3815-
executed internally when all data has been fetched. If you need to be
3816-
able to stop a query before retrieving all data, use a
3817-
[ResultSet with callbacks](#resultsethandling). (Note: An
3818-
experimental `querystream._close()` method exists to terminate a
3819-
stream early. It is under evaluation, may changed or be removed, and
3820-
should not be used in production.)
3811+
Class](#resultsetclass). In particular, successive calls to
3812+
[getRow()](#getrow) are made internally. Each row will generate a
3813+
`data` event. For tuning, adjust the value of
3814+
[`oracledb.fetchArraySize`](#propdbfetcharraysize) or the `execute()`
3815+
option [`fetchArraySize`](#propexecfetcharraysize).
38213816
38223817
An example of streaming query results is:
38233818
@@ -6759,8 +6754,16 @@ When upgrading from node-oracledb version 1.13 to version 2.0:
67596754
- Test applications to check if changes such as the improved property
67606755
validation uncover latent problems in your code.
67616756
6757+
## <a name="migratev20v21"></a> 24. Migrating from node-oracledb 2.0 to node-oracledb 2.1
6758+
6759+
When upgrading from node-oracledb version 2.0 to version 2.1:
67626760
6761+
- If using the experimental `_close` method with [Query
6762+
Streaming](#streamingresults) in Node 8 or later:
67636763
6764+
- Change the method name from `_close()` to [`destroy()`][92].
6765+
- Stop passing a callback.
6766+
- Optionally pass an error.
67646767
67656768
[1]: https://www.npmjs.com/package/oracledb
67666769
[2]: https://github.com/oracle/node-oracledb/blob/master/INSTALL.md
@@ -6853,3 +6856,4 @@ When upgrading from node-oracledb version 1.13 to version 2.0:
68536856
[89]: https://github.com/oracle/node-oracledb/tree/master/examples/dbconfig.js
68546857
[90]: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/admin/getting-started-with-database-administration.html#GUID-5F1E393E-97B8-43BC-BD68-3595251A6F7C
68556858
[91]: https://www.youtube.com/watch?v=WDJacg0NuLo
6859+
[92]: https://nodejs.org/api/stream.html#stream_readable_destroy_error

lib/connection.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@ function queryStream(sql, binding, options) {
5353

5454
stream = new QueryStream(null, self._oracledb);
5555

56-
if (options.fetchArraySize) {
57-
stream._fetchArraySize = options.fetchArraySize;
58-
}
59-
6056
self._execute(sql, binding, options, function(err, result) {
6157
if (err) {
6258
stream._open(err, null);
6359
} else {
64-
resultset.extend(result.resultSet, self._oracledb);
60+
resultset.extend(result.resultSet, self._oracledb, options);
6561
stream._open(null, result.resultSet);
6662
}
6763
});

0 commit comments

Comments
 (0)