We added a new JavaScript layer in the last release of the Node.js driver for Oracle Database. It added just one feature (connection request queueing) and didn’t include any API changes. However, there are currently two features being worked on that could bring such changes: ResultSet Streaming and Optional Promise Support.

ResultSet Streaming

The ResultSet class is an important class in the driver that allows people to paginate through large result sets with read consistency. The current API to process ResultSets requires the use of recursive function calls. Depending on one’s background, this may or may not be the most intuitive way to work with large result sets.

Sagie Gur-Ari is working on ResultSet streaming, an alternative API based on Readable streams in Node.js. Currently, it appears the API will be implemented via a new method named queryStream. Unlike other methods in the driver which are async and pass their results back to the JavaScript layer via callback functions, queryStream immediately returns a readable stream that can be setup to start processing data.

Here’s an example of what it currently looks like to process a ResultSet using the recursive API:

And here’s an example of what it might look like to process a ResultSet using the new queryStream method:

Personally, in the case of processing ResultSets, I think the streaming API is a better metaphor and is a bit more intuitive. Nice work Sagie!

Here’s a link to the PR for ResultSet streaming. If this feature interests you please test it out and let us know how it goes.

Optional Promise Support

The other feature we’re working on is Optional Promise Support. I say “optional” because I want to make it clear that no one will be forced to use promises with async methods – the callback pattern will remain the default. However, promises in JavaScript are quite common at this point and many developers are starting to expect direct support in the modules they use so they don’t have to do much to start leveraging them.

We’ve implemented this feature using a “promisify” method that extends the current async methods so they return promises when callback functions are not provided. This makes the API easier to use as there are no new method names, just don’t supply a callback and you’ll get a promise returned synchronously.

It’s also possible to swap out the default Promise implementation by setting oracledb.Promise to your favorite promise library.

Here’s an example of what it looks like to use the current, callback based API to process a basic query:

And here’s what it might look like if optional promise support lands in the driver:

If your interested in taking the promise support for a spin, checkout this fork. Please let us know if you find any issues or if things work as expected (always good to know)! 🙂

In the end, both of these features are really just syntactic sugar on top of the core APIs. We hope they will provide JavaScript developers with options that fit their preferred development style and make for a more pleasant experience working with the driver. Your feedback and suggestions on these features would be greatly appreciated. Thanks!

Leave a Reply