tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 465 forks source link

Recordset and Recordsets missing when streaming #1499

Closed sleepinzombie closed 1 year ago

sleepinzombie commented 1 year ago

I am currently using the streaming method to select 15000+ data from a table. However, recordset and recordsets are missing in the done event.

Expected behaviour:

recordset and recordsets should be present in the result of the done event.

Actual behaviour:

Only output and rowsAffected are present. But I can see the console logs for event row logged me the data objects (data from the DB).

Configuration:

This is my code I am using to select the data.

MSSql.connect(sqlConfig, (err) => {
      const request = new MSSql.Request();
      request.stream = true; // You can set streaming differently for each request
      request.query('select * from booking'); // or

      request.on('recordset', (columns) => {
        // Emitted once for each recordset in a query
        //console.log(columns);
      });

      let rowsToProcess = [];

      request.on('row', (row) => {
        // Emitted for each row in a recordset
        rowsToProcess.push(row);
        if (rowsToProcess.length >= 3) {
          request.pause();
          processRows();
        }
        console.log(row);
      });

      request.on('error', (err) => {
        // May be emitted multiple times
        console.log(err);
      });

      request.on('done', (result) => {
        // Always emitted as the last one
        processRows();
        console.log(result);
      });

      const processRows = () => {
        // process rows
        rowsToProcess = [];
        request.resume();
      };
    });

And the response is as follows:

image

Software versions

dhensby commented 1 year ago

There is no feature where the records are available in the dive event when streaming.

The point of streaming is that you can use it on large results and not have the library consume large amounts of memory by hiding every row in memory.

You have all the rows available to you in the row event.