You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After investigating the pause / resume functionality for our existing Request objects, I looked into what it would take to turn them into bonafide streams instead of a semi-ducktyped stream.
Current issues
At the moment the Request class is quite complicated and has sprinklings of if (this.stream) throughout and I feel we could greatly simplify the core logic by moving to a "stream first" implementation where Requests could be promisified on demand.
The Requests from tedious are essentially streams, so this would allow us to interface with them in a more straightforward fashion.
The current stream implementation we have doesn't work particularly well if you also want to make use of the promise functionality, so we need to clear up that usage a bit more too.
Changes required
Request object extends stream.Readable
Stream operates in object mode
Add promise transformation method to Request
Impact
Deprecation of row event and replaced with data event (generally conform to the Stream interface)
Requests will not be promises by default
Challenges
Error handling
msnodesqlv8 doesn't support resume/pause of requests
Also alternative approach is not to make the request itself a stream but to make the object that the request.query() (and other methods) return a stream if request.stream is set to true...
Also alternative approach is not to make the request itself a stream but to make the object that the request.query() (and other methods) return a stream if request.stream is set to true...
Is there a tangible benefit to making Requests first class streams?
I don't think so, for BC reasons and also because we're supporting two drivers, one of which hasn't got stream support.
Shouldn't tedious be implementing a first class stream object too?
Probably...
Is a readable stream the right type of stream? Should it be a transform stream with the tedious request as the input stream?
Following on from our discussion, I think a transformable stream makes sense here if we're considering wider use cases.
Do we want to patch msnodesqlv8 to implement pause/resume or do we want to drop it as a driver?
My understanding is that we could start to look at dropping it for future releases because Tedious now supports domain logon which is what msnodesql8 was distinct in supporting. @patriksimek might know better though!
Following on from our discussion, I think a transformable stream makes sense here if we're considering wider use cases.
We have to provide the transformer if that's the case. Someone else can use our readable stream and implement it in a Transformer Stream to transform it into their own output. My research tells me readable stream is correct
So this is blocked until TimelordUK/node-sqlserver-v8#89 is resolved OR we just return a stream from results already loaded in memory..
The latter would allow us to return a true stream but it would mean there was no performance gain for developers using the msnodesqlv8 driver (though it wouldn't be any worse than it is now)
Any progress on this?
Can't use it as a regular node stream yet (6.0.0-beta.1) even though TimelordUK/node-sqlserver-v8#89 is closed.
What I mean by "regular" is using ".pipe" and "for await ... of".
There has been progress to an extent. We don't return a true node stream but we do expose a reliable API that allows you to pause the result stream across the two supported drivers (sqlserver-v8 and tedious).
It's not going to be in v6 where we actually return a real stream, for now you'll have to wrap our request objects in your own ReadableStream and implement the backpressure logic (pretty simple to do).
This change to the API would be a bit too sweeping and require too much work to go into v6, especially as we are now in beta
Can you please add information to the docs that this is not a real stream and it is just some custom "request"?
Because I thought it is the usual nodejs stream (it actually has the same methods like pause, resume and some events) and have wasted few days debugging my app.
"Streaming" part of the docs.
It shows the same methods as usual nodejs stream has.
It is not stated that this is a "real" stream, however I thought so because functionality is very similar.
Maybe it is only me, but maybe somebody will think the same way and will try to use it like a regular stream.
I have added a PR that may help with these issues if you are using the pipe method. My PR wraps the original request in a Node.js Readable stream which supports back pressure and pipes that to the the incoming stream. #1078
Activity
dhensby commentedon Jan 4, 2019
I guess my initial questions are:
msnodesqlv8to implement pause/resume or do we want to drop it as a driver?dhensby commentedon Jan 4, 2019
Also alternative approach is not to make the request itself a stream but to make the object that the
request.query()(and other methods) return a stream ifrequest.streamis set to true...dhensby commentedon Jan 7, 2019
I'm starting to think this is a better idea
willmorgan commentedon Jan 7, 2019
I don't think so, for BC reasons and also because we're supporting two drivers, one of which hasn't got stream support.
Probably...
Following on from our discussion, I think a transformable stream makes sense here if we're considering wider use cases.
My understanding is that we could start to look at dropping it for future releases because Tedious now supports domain logon which is what msnodesql8 was distinct in supporting. @patriksimek might know better though!
dhensby commentedon Jan 7, 2019
We have to provide the transformer if that's the case. Someone else can use our readable stream and implement it in a Transformer Stream to transform it into their own output. My research tells me readable stream is correct
dhensby commentedon Jan 7, 2019
I've created a POC for stream objects here: master...dhensby:pulls/stream-first
patriksimek commentedon Jan 7, 2019
@willmorgan I believe msnodesqlv8 performed much better since it's a native module. But it may not be true anymore with latest changes to Tedious.
dhensby commentedon Mar 12, 2019
So this is blocked until TimelordUK/node-sqlserver-v8#89 is resolved OR we just return a stream from results already loaded in memory..
The latter would allow us to return a true stream but it would mean there was no performance gain for developers using the msnodesqlv8 driver (though it wouldn't be any worse than it is now)
[-]RFC - Turn Request objects into first class stream objects[/-][+]RFC - Provide true node streams[/+]jansivans commentedon Sep 6, 2019
Any progress on this?
Can't use it as a regular node stream yet (6.0.0-beta.1) even though TimelordUK/node-sqlserver-v8#89 is closed.
What I mean by "regular" is using ".pipe" and "for await ... of".
dhensby commentedon Sep 6, 2019
There has been progress to an extent. We don't return a true node stream but we do expose a reliable API that allows you to pause the result stream across the two supported drivers (sqlserver-v8 and tedious).
It's not going to be in v6 where we actually return a real stream, for now you'll have to wrap our request objects in your own ReadableStream and implement the backpressure logic (pretty simple to do).
This change to the API would be a bit too sweeping and require too much work to go into v6, especially as we are now in beta
jansivans commentedon Sep 6, 2019
Can you please add information to the docs that this is not a real stream and it is just some custom "request"?
Because I thought it is the usual nodejs stream (it actually has the same methods like pause, resume and some events) and have wasted few days debugging my app.
dhensby commentedon Sep 6, 2019
What part of the library presents itself as a "real" stream but isn't actually? I'm happy to accept docs amendments you think are appropriate
jansivans commentedon Sep 6, 2019
"Streaming" part of the docs.
It shows the same methods as usual nodejs stream has.
It is not stated that this is a "real" stream, however I thought so because functionality is very similar.
Maybe it is only me, but maybe somebody will think the same way and will try to use it like a regular stream.
jeffbski-rga commentedon Jul 29, 2020
I have added a PR that may help with these issues if you are using the
pipemethod. My PR wraps the original request in a Node.js Readable stream which supports back pressure and pipes that to the the incoming stream. #1078dhensby commentedon Nov 19, 2020
this was fixed in #1078