Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chdh opened this issue Jul 5, 2023 · 4 comments
Open

Comments

@chdh
Copy link
Collaborator

chdh commented Jul 5, 2023

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);
}
@arthurschreiber
Copy link
Collaborator

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?

@chdh
Copy link
Collaborator Author

chdh commented Jul 5, 2023

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.

@chdh
Copy link
Collaborator Author

chdh commented Jul 6, 2023

@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?

@arthurschreiber
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants