其实我们使用的是SAP针对SAP HANA Express Editor发布的nodejs SDK.
npm init创建一个新的nodejs应用:
执行下列命令行,从SAP的nodejs registry下载hana client:
npm config set @sap:registry https://npm.sap.com
npm install @sap/hana-client
安装完毕:
使用require导入sap hana client,在nodejs代码里使用其对HANA Express发起查询:
const hanaClient = require("@sap/hana-client");
const connection = hanaClient.createConnection();
const connectionParams = {
host : "hxehost",
port : 39013,
uid : "SYSTEM",
pwd : "********",
databaseName : "HXE"
}
connection.connect(connectionParams, (err) => {
if (err) {
return console.error("Connection error", err);
}
const whereClause = process.argv[2] ? `WHERE "group" = '${process.argv[2]}'` : "";
const sql = `SELECT "name" FROM food_collection ${whereClause}`;
connection.exec(sql, (err, rows) => {
connection.disconnect();
if (err) {
return console.error('SQL execute error:', err);
}
console.log("Results:", rows);
console.log(`Query '${sql}' returned ${rows.length} items`);
});
});
执行该应用,返回从SAP HANA Express查询的结果:
本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。