Repository navigation
AsyncRowIterator.Class.AsyncRowIterator
tedious-plus / AsyncRowIterator / AsyncRowIterator
Defined in: AsyncRowIterator.ts:76
An async iterator for the result rows of a Tedious Request.
The iterator must be created before the request is executed, so that it does not miss any events of
the request. The request can then be executed, e.g. with connection.execSql().
Usage:
const request = new Tedious.Request("select name from sys.databases", () => {});
const iterator = new AsyncRowIterator(request);
connection.execSql(request);
for await (const row of iterator) {
console.log(row);
}The type declarations of the current Tedious version require a completion callback for the
Request constructor. The dummy callback () => {} in the example above can be omitted once
Tedious makes it optional.
Behavior:
- By default, each row is delivered as an object (
ObjectRow). Other row formats can be selected with the option AsyncRowIteratorOptions.rowType. - Only the first result set of the request is processed. Additional result sets are ignored.
- The rows received from the server are buffered in an internal FIFO. When the FIFO is full, the request is paused until enough rows have been consumed (see AsyncRowIteratorOptions.fifoSize).
- When the request fails, e.g. because of an SQL error, the rows received before the error are delivered
first. Then the error is thrown within the
for awaitloop, i.e. the promise returned bynext()is rejected. - When the
for awaitloop is exited early (bybreak,returnor an exception), the request is canceled. The loop exit waits until the request has completed, so that the connection can be used for the next request immediately afterwards.
Requirements:
The connection options useColumnNames, rowCollectionOnDone and rowCollectionOnRequestCompletion
must not be set. Otherwise the iteration fails with an error.
RT extends RowType = "ObjectRow"
AsyncDisposable
new AsyncRowIterator<RT>(request, options?): AsyncRowIterator<RT>;Defined in: AsyncRowIterator.ts:91
Creates a row iterator for a Tedious request.
Request
The Tedious request whose result rows are to be iterated.
Optional settings for the iterator, e.g. the row type.
AsyncRowIterator<RT>
get fifoRowCount(): number;Defined in: AsyncRowIterator.ts:109
Returns the number of rows that have been received from the server, but not yet delivered by the iterator. These rows are stored in the internal FIFO row buffer.
number
get metadata(): Tedious_ArrayRowMetadata;Defined in: AsyncRowIterator.ts:120
Returns the row metadata of the first result set.
The metadata is guaranteed to be available when the first row is delivered.
Error If the metadata has not yet been received.
Tedious_ArrayRowMetadata
get objectRowMetadata(): ObjectRowMetadata;Defined in: AsyncRowIterator.ts:131
Returns the row metadata of the first result set as an object with one property per column.
Error If the metadata has not yet been received.
get rowCount(): number;Defined in: AsyncRowIterator.ts:102
Returns the number of rows that have been delivered by the iterator so far.
number
[asyncDispose](): Promise<void>;Defined in: AsyncRowIterator.ts:169
Terminates the iteration. This method is called implicitly at the end of the scope of an
await using declaration.
If the request is still active, it is canceled. The returned promise is resolved when the request
has completed, so that the connection can be used for the next request immediately afterwards.
This has the same effect as exiting a for await loop early.
Usage:
await using iterator = ConnectionPromises.execSqlIterator(connection, request);
const metadata = await iterator.getMetadata();
...Promise<void>
AsyncDisposable.[asyncDispose]
[asyncIterator](): AsyncIterator<Row<RT>>;Defined in: AsyncRowIterator.ts:151
Returns the AsyncIterator for the rows. This method is called implicitly by a for await loop.
The same iterator object is returned on each call.
AsyncIterator<Row<RT>>
getMetadata(): Promise<Tedious_ArrayRowMetadata>;Defined in: AsyncRowIterator.ts:143
Returns a promise for the row metadata of the first result set.
The returned promise is resolved as soon as the metadata has been received, which is before the first row is delivered. It is rejected if the request completes without producing a result set, e.g. because of an error, because the SQL statement does not produce a result set, or because the iteration has been terminated early.
Promise<Tedious_ArrayRowMetadata>