Skip to content

AsyncRowIterator.Class.AsyncRowIterator

Christian d'Heureuse edited this page Oct 28, 2026 · 2 revisions

tedious-plus / AsyncRowIterator / AsyncRowIterator

Class: AsyncRowIterator<RT>

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 await loop, i.e. the promise returned by next() is rejected.
  • When the for await loop is exited early (by break, return or 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.

Type Parameters

RT

RT extends RowType = "ObjectRow"

Implements

  • AsyncDisposable

Constructors

Constructor

new AsyncRowIterator<RT>(request, options?): AsyncRowIterator<RT>;

Defined in: AsyncRowIterator.ts:91

Creates a row iterator for a Tedious request.

Parameters

request

Request

The Tedious request whose result rows are to be iterated.

options?

AsyncRowIteratorOptions<RT>

Optional settings for the iterator, e.g. the row type.

Returns

AsyncRowIterator<RT>

Accessors

fifoRowCount

Get Signature

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.

Returns

number


metadata

Get Signature

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.

Throws

Error If the metadata has not yet been received.

Returns

Tedious_ArrayRowMetadata


objectRowMetadata

Get Signature

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.

Throws

Error If the metadata has not yet been received.

Returns

ObjectRowMetadata


rowCount

Get Signature

get rowCount(): number;

Defined in: AsyncRowIterator.ts:102

Returns the number of rows that have been delivered by the iterator so far.

Returns

number

Methods

[asyncDispose]()

[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();
...

Returns

Promise<void>

Implementation of

AsyncDisposable.[asyncDispose]


[asyncIterator]()

[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.

Returns

AsyncIterator<Row<RT>>


getMetadata()

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.

Returns

Promise<Tedious_ArrayRowMetadata>

Clone this wiki locally