@@ -3703,11 +3703,11 @@ This function provides query streaming support. The parameters are
3703
3703
the same as [`execute()`](#execute) except a callback is not used.
3704
3704
Instead this function returns a stream used to fetch data.
3705
3705
3706
- Each row is returned as a `data` event. Query metadata is available
3707
- via a `metadata` event. The `end` event indicates the end of the
3708
- query results.
3709
-
3710
- The connection must remain open until the stream is completely read .
3706
+ Each row is returned as a `data` event. Query metadata is available via a
3707
+ `metadata` event. The `end` event indicates the end of the query results. The
3708
+ connection must remain open until the stream is completely read and the `close`
3709
+ event received. Alternatively the Stream [`destroy()`][92] method can be used
3710
+ to terminate a stream early .
3711
3711
3712
3712
For tuning, adjust the value of
3713
3713
[`oracledb.fetchArraySize`](#propdbfetcharraysize) or the
@@ -8841,22 +8841,23 @@ await rs.close();
8841
8841
Streaming of query results allows data to be piped to other streams,
8842
8842
for example when dealing with HTTP responses.
8843
8843
8844
- Use [`connection.queryStream()`](#querystream) to create a stream from
8845
- a top level query and listen for events. You can also call
8846
- [`connection.execute()`](#execute) and use
8847
- [`toQueryStream()`](#toquerystream) to return a stream from the
8848
- returned [ ResultSet](#resultsetclass), an OUT bind REF CURSOR
8849
- ResultSet, or [Implicit Results](#implicitresults) ResultSet .
8844
+ Use [`connection.queryStream()`](#querystream) to create a stream from a top
8845
+ level query and listen for events. You can also call
8846
+ [`connection.execute()`](#execute) and use [`toQueryStream()`](#toquerystream)
8847
+ to return a stream from the returned [ResultSet](#resultsetclass), from an OUT
8848
+ bind REF CURSOR ResultSet, or from [Implicit Results](#implicitresults)
8849
+ ResultSets .
8850
8850
8851
- With streaming, each row is returned as a `data` event. Query
8852
- metadata is available via a `metadata` event. The `end` event
8853
- indicates the end of the query results.
8851
+ With streaming, each row is returned as a `data` event. Query metadata is
8852
+ available via a `metadata` event. The `end` event indicates the end of the
8853
+ query results, however it is generally best to put end-of-fetch logic in the
8854
+ `close` event.
8854
8855
8855
8856
Query results should be fetched to completion to avoid resource leaks, or the
8856
- Stream [`destroy()`][92] method can be used to terminate a stream early.
8857
-
8858
- The connection must remain open until the stream is completely read
8859
- and any returned [Lob](#lobclass) objects have been processed.
8857
+ Stream [`destroy()`][92] method can be used to terminate a stream early. When
8858
+ fetching, the connection must remain open until the stream is completely read
8859
+ and the `close` event received. Any returned [Lob](#lobclass) objects should
8860
+ also be processed first .
8860
8861
8861
8862
The query stream implementation is a wrapper over the [ResultSet
8862
8863
Class](#resultsetclass). In particular, successive calls to
@@ -8879,7 +8880,11 @@ stream.on('data', function (data) {
8879
8880
});
8880
8881
8881
8882
stream.on('end', function () {
8882
- // release connection...
8883
+ // all data has been fetched...
8884
+ });
8885
+
8886
+ stream.on('close', function () {
8887
+ // can now close connection... (Note: do not close connections on 'end')
8883
8888
});
8884
8889
8885
8890
stream.on('metadata', function (metadata) {
0 commit comments