Losing data with streaming pause / resume
See original GitHub issueHi, I followed the example on Github on how to use pause / resume. First of all I have to add :any to const request otherwise I get the error “The property ‘pause’ (resume) does not exist on type ‘Request’.” Instead of just emptying the rowsToProcess array I add the content to a new rowsToShow array. But in the end there are entries missing. There should be about 215.000 entries which are all shown if I don’t stream them but depending on the length (15 -100 entries) I use as a cut off there are only 207.000 to 210.000 entries. It looks that the pause/resume function does not work properly or maybe doesn’t work at all and while the processRows() is executed the data continues to be streamed and gets lost. Or did I miss something?
Also the memory usage when using stream and pause/resume is just about the same as when using the normal version.
import mssql = require(‘mssql’) import {pool} from ‘./pool’
const request:any = new mssql.Request(pool)
request.stream = true
let rowsToProcess:any = []
let rowsToShow:any = []
request.query(SELECT * FROM DummyTable
)
request.on('row', (row:any) => {
if (rowsToProcess.length < 15) {
rowsToProcess.push(row)
}
else {
request.pause()
processRows()
}
})
request.on('done', () => {
rowsToShow.push(...rowsToProcess) //adds the last rowsToProcess to rowsToShow
console.log(rowsToShow.length) // number of entries in rowsToShow
res.json(rowsToShow.slice(0,100)) // shows the first 100 entries
})
function processRows() {
rowsToShow.push(...rowsToProcess)
rowsToProcess = []
request.resume()
}
- NodeJS: 10.15.0
- node-mssql: 5.0.0.alpha4
- SQL Server: 2017
Can anybody help me out here? Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:13
RE the
:any
casting issue, that’s most likely a typescript issue and so for the https://github.com/DefinitelyTyped/DefinitelyTyped repo not this library.So marking this as fixed
@gsamal v5.0.0-beta.1 tagged 😃