This guide describes:

  • The required prerequisistes, and installation of the SQream Node.js driver.

  • How to create and maintain a connection to SQream DB for a Node.js application.

1. Prerequisites: Node.js 8.x

Install node.js version 8.x

Recommendation: Use latest node.js 8.x version.

2. Install the SQream Node.js Driver

  • Download the SQream Node.js driver file: sqream-connector-[version].tgz.

  • Install or upgrade the driver with npm install from file.

For example:

sudo npm install sqream-connector-1.5.0.tgz

3. Create a connection to Sqream DB

Create a node.js file to configure your connection. Make sure to edit the required details, such as <your server address>, <your server port>, <your username> and <your password>, etc.

For example: node_connector.js

Example:

const Connection = require('sqream-connector');
const config = {
  host: '<your server address>',
  port: <your server port>,
  username: '<your server port>',
  password: '<your password>',
  connectDatabase: '<your database>',
  cluster: '<true/false>',
  };
  const query1 = "SELECT 1 as test, 2 as other_test";
  const myConnection = new Connection(config);
  myConnection.runQuery(query1, function (err, data){
  console.log(err, data);
});

4. Connect to SQream DB using Node.js

For example:

node node_connector.js

On a successful connection, you should see:

null [ { test: 1, other_test: 2 } ]

5. Events

The sqream-connector has a few events return with event emitter.

5.1. getConnectionId

getConnectionId event return the executing connection Id.

5.2. getStatementId

getStatementId event return the executing statement Id

5.3. getTypes

getTypes event return the results columns types

5.4. Event Examples

const myConnection = new Connection(config);

myConnection.runQuery(query1, function (err, data){
  myConnection.events.on('getConnectionId', function(data){
      console.log('getConnectionId', data);
  });

  myConnection.events.on('getStatementId', function(data){
      console.log('getStatementId', data);
  });

  myConnection.events.on('getTypes', function(data){
      console.log('getTypes', data);
  });
});

6. Set Statement Flag

You can add a 'SET' flag to statements inside 'runQuery'.

const setFlag = 'SET showfullexceptioninfo = true;'

const myConnection = new Connection(config);
myConnection.runQuery(query1, function (err, data){
  console.log(err, data);
}, setFlag);

The node application which utilizes the sqream connector should consider the heap size node configuration.

When processing large datasets, it is recommended to increase the application heap size with the "--max_old_space_size" node run flag:

node --max_old_space_size={heapSize} my-application.js

The following error message indicates that the heap size configured is not sufficient:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Copyright © 2010-2018. All rights reserved.

This document is provided for information purposes only and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in law, including implied warranties and conditions of merchant- ability or fitness for a particular purpose.

We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document.

This document may not be reproduced in any form, for any purpose, without our prior written permission.