@sap/hana-client
Official SAP HANA Node.js Driver
$ npm install @sap/hana-client 
SYNC missed versions from official npm registry.

@sap/hana-client

Fully-featured Node.js driver for SAP HANA. It is used to connect, issue SQL queries, and obtain result sets.

Install

npm install @sap/hana-client

Prerequisites

This driver communicates with the native HANA libraries, and thus requires platform-specific native binaries. The official hosted version includes precompiled libraries for Linux, Windows and Mac OS X.

The @sap/hana-client driver supports versions of Node.js 16 and higher.

Community

SAP Community provides a forum where you can ask and answer questions, and comment and vote on the questions of others and their answers.

See SAP HANA Community Questions for details.

Help Guide

The SAP HANA Node.js Driver help guide and API reference can be found on help.sap.com.

Getting Started

var hana = require('@sap/hana-client');

var conn = hana.createConnection();

var conn_params = {
  serverNode  : 'myserver:30015',
  uid         : 'system',
  pwd         : 'Password123'
};

conn.connect(conn_params, function(err) {
  if (err) throw err;
  conn.exec('SELECT Name, Description FROM Products WHERE id = ?', [301], function (err, result) {
    if (err) throw err;

    console.log('Name: ', result[0].Name, ', Description: ', result[0].Description);
    // output --> Name: Tee Shirt, Description: V-neck
    conn.disconnect();
  })
});

Establish a database connection

Connecting

A database connection object is created by calling createConnection. The connection is established by calling the connection object's connect method, and passing in an object representing connection parameters.

Example: Connecting over TCP/IP

conn.connect({
  host    : 'myserver',
  port    : '30015',
  uid     : 'system',
  pwd     : 'Password123'
});

Disconnecting

conn.disconnect(function(err) {
  if (err) throw err;
  console.log('Disconnected');
});

Direct Statement Execution

Direct statement execution is the simplest way to execute SQL statements. The inputs are the SQL command to be executed, and an optional array of positional arguments. The result is returned using callbacks. The type of returned result depends on the kind of statement.

DDL Statement

In the case of a successful DDL Statement, nothing is returned.

conn.exec('CREATE TABLE Test (id INTEGER PRIMARY KEY, msg VARCHAR(128))', function (err, result) {
  if (err) throw err;
  console.log('Table Test created!');
});

DML Statement

In the case of a DML Statement the number of affectedRows is returned.

conn.exec("INSERT INTO Test VALUES(1, 'Hello')", function (err, affectedRows) {
  if (err) throw err;
  console.log('Number of affected rows:', affectedRows);
});

Query

The exec function is a convenient way to completely retrieve the result of a query. In this case all selected rows are fetched and returned in the callback.

conn.exec("SELECT * FROM Test WHERE id < 5", function (err, rows) {
  if (err) throw err;
  console.log('Rows:', rows);
});

Values in the query can be substitued with JavaScript variables by using ? placeholders in the query, and passing an array of positional arguments.

conn.exec("SELECT * FROM Test WHERE id BETWEEN ? AND ?", [5, 8], function (err, rows) {
  if (err) throw err;
  console.log('Rows:', rows);
});

Prepared Statement Execution

Prepare a Statement

The connection returns a statement object which can be executed multiple times.

conn.prepare('SELECT * FROM Test WHERE id = ?', function (err, stmt){
  if (err) throw err;
  // do something with the statement
});

Execute a Statement

The execution of a prepared statement is similar to the direct statement execution. The first parameter of exec function is an array with positional parameters.

stmt.exec([16], function(err, rows) {
  if (err) throw err;
  console.log("Rows: ", rows);
});

Execute a Batch Statement

The execution of a prepared batch statement is similar to the direct statement execution. The first parameter of execBatch function is an array with positional parameters.

var stmt=conn.prepare("INSERT INTO Customers(ID, NAME) VALUES(?, ?)");
stmt.execBatch([[1, 'Company 1'], [2, 'Company 2']], function(err, rows) {
  if (err) throw err;
  console.log("Rows: ", rows);
});

Execute a Query

The execution of a prepared query is similar to the direct statement execution. The first parameter of execQuery function is an array with positional parameters.

var stmt=conn.prepare("SELECT * FROM Customers WHERE ID >= ? AND ID < ?");
stmt.execQuery([100, 200], function(err, rs) {
  if (err) throw err;
    var rows = [];
    while (rs.next()) {
      rows.push(rs.getValues());
    }
  console.log("Rows: ", rows);
});

Drop Statement

stmt.drop(function(err) {
  if (err) throw err;
});

Transaction Handling

Transactions are automatically commited. Setting autocommit to false implicitly starts a new transaction that must be explicitly committed, or rolled back.

Commit a Transaction

conn.setAutoCommit(false);
// Execute some statements
conn.commit(function(err) {
  if (err) throw err;
  console.log('Transaction commited.');
});

Rollback a Transaction

conn.setAutoCommit(false);
// Execute some statements
conn.rollback(function(err) {
  if (err) throw err;
  console.log('Transaction rolled back.');
});

Resources

License

The HANA Node.js Driver is provided via the SAP Developer License Agreement.

By using this software, you agree that the following text is incorporated into the terms of the Developer Agreement:

If you are an existing SAP customer for On Premise software, your use of this current software is also covered by the terms of your software license agreement with SAP, including the Use Rights, the current version of which can be found at: https://www.sap.com/about/agreements/product-use-and-support-terms.html?tag=agreements:product-use-support-terms/on-premise-software/software-use-rights

Current Tags

  • 2.22.29                                ...           latest (a month ago)

83 Versions

  • 2.22.29                                ...           a month ago
  • 2.22.27                                ...           2 months ago
  • 2.21.31                                ...           3 months ago
  • 2.21.28                                ...           4 months ago
  • 2.21.26                                ...           5 months ago
  • 2.20.23                                ...           6 months ago
  • 2.20.22                                ...           6 months ago
  • 2.20.20                                ...           7 months ago
  • 2.20.15                                ...           8 months ago
  • 2.19.21                                ...           10 months ago
  • 2.19.20                                ...           a year ago
  • 2.19.18                                ...           a year ago
  • 2.18.27                                ...           a year ago
  • 2.18.24                                ...           a year ago
  • 2.18.22                                ...           a year ago
  • 2.17.22                                ...           a year ago
  • 2.17.21                                ...           a year ago
  • 2.17.14                                ...           a year ago
  • 2.16.26                                ...           2 years ago
  • 2.16.21                                ...           2 years ago
  • 2.15.22                                ...           2 years ago
  • 2.15.19                                ...           2 years ago
  • 2.15.17                                ...           2 years ago
  • 2.14.24                                ...           2 years ago
  • 2.14.23                                ...           2 years ago
  • 2.14.22                                ...           2 years ago
  • 2.14.18                                ...           2 years ago
  • 2.13.22                                ...           2 years ago
  • 2.13.21                                ...           2 years ago
  • 2.13.13                                ...           2 years ago
  • 2.12.25                                ...           3 years ago
  • 2.12.22                                ...           3 years ago
  • 2.12.20                                ...           3 years ago
  • 2.12.13                                ...           3 years ago
  • 2.11.20                                ...           3 years ago
  • 2.11.14                                ...           3 years ago
  • 2.10.20                                ...           3 years ago
  • 2.10.15                                ...           3 years ago
  • 2.10.13                                ...           3 years ago
  • 2.10.9                                ...           3 years ago
  • 2.9.28                                ...           3 years ago
  • 2.9.23                                ...           3 years ago
  • 2.9.19                                ...           3 years ago
  • 2.8.22                                ...           3 years ago
  • 2.8.20                                ...           4 years ago
  • 2.8.16                                ...           4 years ago
  • 2.7.26                                ...           4 years ago
  • 2.7.23                                ...           4 years ago
  • 2.7.21                                ...           4 years ago
  • 2.7.16                                ...           4 years ago
  • 2.6.64                                ...           4 years ago
  • 2.6.61                                ...           4 years ago
  • 2.6.58                                ...           4 years ago
  • 2.6.54                                ...           4 years ago
  • 2.5.111                                ...           4 years ago
  • 2.5.109                                ...           4 years ago
  • 2.5.105                                ...           4 years ago
  • 2.5.104                                ...           4 years ago
  • 2.5.101                                ...           4 years ago
  • 2.5.86                                ...           4 years ago
  • 2.4.202                                ...           4 years ago
  • 2.4.139                                ...           4 years ago
  • 2.3.144                                ...           4 years ago
  • 2.4.155                                ...           4 years ago
  • 2.3.119                                ...           4 years ago
  • 2.4.144                                ...           4 years ago
  • 2.3.106                                ...           4 years ago
  • 2.3.112                                ...           4 years ago
  • 2.3.21                                ...           4 years ago
  • 2.4.151                                ...           4 years ago
  • 2.4.167                                ...           4 years ago
  • 2.3.123                                ...           4 years ago
  • 2.3.134                                ...           4 years ago
  • 2.4.196                                ...           4 years ago
  • 2.3.130                                ...           4 years ago
  • 2.4.126                                ...           4 years ago
  • 2.4.142                                ...           4 years ago
  • 2.4.162                                ...           4 years ago
  • 2.4.194                                ...           5 years ago
  • 2.4.191                                ...           5 years ago
  • 2.4.182                                ...           5 years ago
  • 2.4.177                                ...           5 years ago
  • 2.4.171                                ...           5 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE