createObjectStream(Object) Function
Creates a node.js readable stream using a result set. The stream returns data as JSON objects.
Parameters
| Type | Name | Description |
|---|---|---|
| Object | resultset | The result set returned by executing a query. |
Remarks
This method creates a node.js stream and returns the data as JSON objects.
Example
Create a readable object stream and fetch data from it.
function fetchObjectStream() {
var conn = openConnection();
var stmt = conn.prepare('SELECT TOP 10 SCHEMA_NAME, TABLE_NAME FROM SYS.TABLES');
var rs = stmt.execQuery();
var hanaStream = require('@sap/hana-client/extension/Stream');
var stream = hanaStream.createObjectStream(rs);
var rows = [];
stream.on('readable', function (data) {
var data;
while (null !== (data = stream.read())) {
rows.push(data);
}
});
stream.on('end', function () {
console.log(rows);
cleanup(conn, stmt, rs);
});
}