Product Documentation

FairCom APIs for Node.js

Previous Topic

Next Topic

Node.js

Introducing Node.js for NAV

Node.js for NAV is a direct navigational database interface for Node.js supporting all the features of the c-treeDB navigational interface ("NAV").

Examples are located in your FairCom DB drivers folder in nodejs.nav.

Example:

const ctdb = require('ctdbsdk');

const {deleteRecords} = require('./deleteRecords');

const {addRecords} = require('./addRecords');

var ref = require('ref-napi');

ctdb.Logon(hSession, "FAIRCOMS", "ADMIN", "ADMIN");

var hDatabase = ctdb.AllocDatabase(hSession);

ctdb.Connect(hDatabase, "ctreeSQL");

var hTable = ctdb.AllocTable(hDatabase);

try {

console.log("Open table...");

ctdb.OpenTable(hTable, "custmast", ctdb.CTOPEN_NORMAL);

} catch(e) {

console.log("Open Failed...");

}

Node.js for SQL

Node.js for SQL allows FairCom DB to be used in a conventional Node.js environment.

Node.js 12 and later supported.

Examples are located in your FairCom DB sdk folder as nodejs.sql.

Example:

const ctsql = require('./ctsql');


ctsql.connect("6597@localhost:ctreeSQL", "admin", "ADMIN");

var result = ctsql.query("SELECT * FROM admin.syscolumns");


console.log(result.columnNames);

console.log(result.rows[0]);

console.log(result.rows[1]);


ctsql.end();

Specify character encoding at connection time

The Node.js interfaces need to properly handle strings with character encoding different than ANSI and UTF-8. An optional parameter for ctsql.Connect specifies the source encoding. If the parameter is present and correctly passed, each string read from the database is converted from the specified character encoding to the Node.JS default UTF-8 using the iconv module. (This implies a dependency on the iconv module.)

TOCIndex