-
Notifications
You must be signed in to change notification settings - Fork 42
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
Detecting "end" of row Streaming? #37
Comments
Its indeed a missing feature, I was planning to add it this week... client.streamRows(query, params, consistency, rowCallback, callback);
//with the definition of the callbacks
client.streamRows(query, params, consistency, function (err, row) {
//gets called per row - AS IS
}, function (err) {
//gets executed when there are no more rows to stream
}); |
Yeah, looks nice like this..... alternatively callback with a null-row and null-error, like MongoDb (Cursor.forEach()) does it. FoundationDB does it like this too (LazyIterator) |
I think the null-row and null-error approach is a bit better because in the other approach you would have some kind of redundant error handling. |
mmm... as you said, I agree that the method signature I'm proposing is no good... I see 2 possibilities: client.streamRows(query, params, consistency, function (n, row) {
//n is the index of the row
//row object
}, function (err, totalRows) {
//the error is only yielded here
//the consumer gets the amount of rows without the need of an internal counter
//for example: if (!totalRows) res.send(404, 'These arent the droids you are looking for');
}); B: cursor.each (mongodb) like: client.streamRows(query, params, consistency, function (err, row) {
//if !err && !row is OEF
}); I see a some use cases
I like possibility A the best. What do you think? |
I would favor B to have a similar function signature as the other db's (to be kind of db agnostic with the callback functions). We directly stream data thru different filters that would reduce the resultset. And we are collecting data from different queries that we push all into the same stream. So we won't need those numbers because we have to check ourselves anyway. A nice interface would be to have the same function for single data callback and streaming as well. riak-js is using an event emitter to return streamed data as far as i know. Perhaps I could write some sample code to explain it in a little more detail if it is unclear. With this approach it should be very easy to push the data in a stream. |
An example usage could be
|
I personally prefer the async version and would be ok with the other-db-like one. Dont like the EventEmitter thing that much, but it would work for me too |
(being data a row object right?) |
Maybe the 2 methods: //async.each type
client.eachRow(query, [params], [consistency], rowCallback, endCallback);
//node-mysql stream like
var stream = client.stream(query, [params], [consistency], endCallback);
//a readable streams2 What do you think? |
Not quite sure when I have enough time to work on that, but will look into it this week. |
I think it would be best to first add the callback for EOF (no more rows) to the existent I will create a new issue for the "Streaming Api Changes" for the |
Made some small changes for the additional null callback: |
I thought we agreed on the extra callback for the The code you wrote is awesome, but the discussion is on a functional level. I would definitely accept any pull request from you if it's aligned with the functionality. |
Implemented by @bitcloud. |
How can i know, that no more rows will come?
I don't want to register a timeout (like "lastReceivedRow") or something, i just want to know, when theres nothing more to stream. Other database-system-drivers would call the callback with null,null. But an event would also be okay.
I dived into code and found out, that the frameParser of the correct connection object would emit some event like this, but even when i think of using this, it smells kind of dirty.
Any suggestions? Or is this some kind of "by design"?
The text was updated successfully, but these errors were encountered: