Home

Awesome

SiriDB-Node.js-Add-on

Node.js add-on (C++) for SiriDB



Installation

node-gyp configure && node-gyp build

Quick usage

const sdbaddon = require('./build/Release/siridb');

var siridb = new sdbaddon.SiriDBClient(
    "iris", "siri", "dbtest", "localhost", 9000);

siridb.connect(err => {
    if (err) {
        console.error(`Connection error: ${err}`);
    } else {
        siridb.close();
    }
});

SiriDBClient

Create a new SiriDB Client. This creates a new client but connect() must be used to connect.

var siridb = new sdbaddon.SiriDBClient(
    "iris",         // database user
    "siri",         // password
    "dbtest",       // database name
    "localhost",    // server address
    9000            // server port
);

SiriDBClient.connect

Connect to SiriDB. A callback function can be used to check if the connect is successful.

siridb.connect(err => {
    // success: err is null
    // error:   err is a string with an error message
    if (err) {
        console.error("Connection error: ", err);
    }
});

SiriDBClient.query

Query SiriDB. Requires a string containing the query and a callback function to catch the result.

The callback function will be called with two arguments:

siridb.query("select * from /.*series/", (resp, status) => {
    // success: status is 0 and resp is an Object containing the data
    // error:   status < 0 and resp.error_msg contains a description about the error
    if (status) {
        console.error(`Query error: ${resp.error_msg} (${status})`);
    } else {
        console.log(resp);  // query data
    }
});

SiriDBClient.insert

Insert time series data into SiriDB. Requires an Array with at least one series Object.string containing the query and a callback function to catch the result.

The callback function will be called with two arguments:

var series = [{
    type: 'float',    // float or integer
    name: 'example',  // name
    points: [         // array with points
        [1505118253, 5.4],  // time-stamp, value
        [1505118307, 7.1]   // etc.
    ]
}];

siridb.insert(series, (resp, status) => {
    // success: status is 0 and resp.success_msg contains a description about the successful insert
    // error:   status < 0 and resp.error_msg contains a description about the error
    if (status) {
        console.error(`Insert error: ${resp.error_msg} (${status})`);
    } else {
        console.log(resp.success_msg);  // insert message
    }
});

SiriDBClient.close

Close the connection.

siridb.close();

Events

SiriDBClient.onClose

Will be triggered when the connction is closed or lost. This event will also be triggered when the connection is closed by the close() function.

siridb.onClose(msg => {
    console.log(msg);  // msg is a String
});

SiriDBClient.onError

Will be triggered only when corrupt or broken data is received on the connection. This is very unlikely to happen but in case something is broken you can use this event to do something, for example close and rebuild the connection.

siridb.onError(msg => {
    console.error(msg);  // msg is a String
});

Status codes

Sometimes its useful to act on a specific error, for example you might want to retry the request in case of ERR_SERVER while a ERR_INSERT error indicates something is wrong with the data.

The following status codes can be returned:

Version info

Use sdbaddon.VERSION for version information.