node.js library that is a thin wrapper around node-odbc to connect to
node-odbc will need a odbc driver to connect to HANA. I have used unixodbc so far. For using it make sure you setup a data source (DSN) that points to a HANA instance. Here is a description for how to setup an odbc connection on Ubuntu.
hana-odbc is on npm, to install it run
$ npm install hana-odbc
If a corporate firewall is bugging npm try
$ npm --proxy http://username:password@proxyservername:port --strict-ssl false install
To install from github do
$ git clone https://github.com/rksm/node-hana-odbc.git
$ cd node-hana-odbc
$ npm install
The test.js
file shows how to connect to and query a database. It
uses the SFLIGHT schema by default. To test if it works make sure your DB
includes this schema and run
$ node test.js username password
server.js
shows how you can provide a HTTP interface with a
expressjs-like backend.
To just use the programatic interface require hana-interface.js
ast it is done in test.js
and server.js
.
Returns an odbc session object for interacting with a HANA database.
Arguments
Example
var session = hanaInterface.getSession({dsn: "DSN=hana;UID=UserName;PWD=Password"});
Establishes a connection to a HANA DB.
Arguments
Example
session.connect(function(err) {
if (err) console.error('Could not connect!');
else console.log('Connection established!');
});
Selects a schema, sends a query, and invokes callback with the query result. If no DB connection is established yet this method will also create a connection.
Arguments
{rows: rows, hasMoreResultSets: moreResultSets}
. The property
rows is an array representing the rows that are the query result.
hasMoreResultSets is a Bool that signals whether there are more results. If
true, callback will be called again with the remaining results.Example
session.query(
'SFLIGHT', "select * from SAPLANE",
function(err, results) {
console.log(JSON.stringify(results, null, 2));
if (!results.hasMoreResultSets)
session.close(console.log.bind(console, 'done'));
});
Ends the connection to a HANA DB.
Arguments
Example
session.close(function(err) {
if (err) console.error('Could not close!');
else console.log('Closed!');
});