tediousjs / tedious

Node TDS module for connecting to SQL Server databases.

Home Page:http://tediousjs.github.io/tedious/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE REQUEST] AsyncIterator for Request class (promise-based streaming)

chdh opened this issue · comments

I suggest to implement an AsyncIterator for the Request class.

This would allow promise-based streaming of query results.

Example of how to use it:

const request = new Request(sql);
connection.execSql(request);
for await (const row of request) {
   console.log(row);
}

This is a great idea, and I've thought about this a bit before. The main problem is that a single Request does not mean you get a single "type" of rows - there's multiple rowstreams which each will come with their own column definitions.

Do you have a suggestion how this could be modeled?

there's multiple rowstreams which each will come with their own column definitions.

A simple solution would be to use the following structure for the items returned by the iterator:

interface RequestIteratorItem {
   row: ColumnValue[] | Record<string, ColumnValue>;
   resultSetNo: number; // 1..n
   columnMetaData: ColumnMetaData[] | Record<string, ColumnMetaData>;
}

The user would have to detect a change in resultSetNo to process the start of a new result set.

@arthurschreiber I already have a working private implementation of an AsyncIterator for the Tedious Request class. I needed the functionality for a client project. I could use it as the basis for a PR.

Would you be interested in a PR from me, or have you already started development yourself?

I'd be happy if you open a PR. 🥳