登录 SAP Business Technology Platform,找到 space 下本人创立好的 HANA Cloud 实例,右键菜单抉择 Copy SQL Endpoint,将 HANA Cloud 实例的 endpoint 拷贝下来:

25eeba68-24ce-4b2d-aaa5-ee8d599ff4a0.hana.trial-eu10.hanacloud.ondemand.com:443

稍后咱们在 Node.js 代码里,会应用到。

新建一个 Node.js 利用,装置 hana client 开发库:

npm install --save @sap/hana-client

残缺的源代码:

var hana = require("@sap/hana-client");var connOptions = {  serverNode: "25eeba68-24ce-4b2d-aaa5-ee8d599ff4a0.hana.trial-eu10.hanacloud.ondemand.com:443",  encrypt: "true",  sslValidateCertificate: "false",  uid: "DBADMIN",  pwd: "Sgd",};var dbConnection = hana.createConnection();dbConnection.connect(connOptions, function (err) {  if (err) throw err;  dbConnection.exec(    `SELECT TOP 1000    "REGION",    "DESCRIPTION"FROM "PLAIN"."REGIONS"`,    function (err, result) {      if (err) throw err;      for( var i = 0; i < result.length; i++)        console.log(result[i]);      dbConnection.disconnect();    }  );});

执行后果:

Node.js 代码里打印的数据库表 REGIONS,来自 PLAIN schema:

留神,应用 DBADMIN 这个用户,只能拜访到该用户领有 access right 的数据库表。

例如咱们更换应用 Node.js 拜访的数据库表名称为 DB1.COMMUNITY:

此时,Node.js 利用报错:

Error: insufficient privilege: Detailed info for this error can be found with guid '6F6F68ED5F58804CB8C7B25D7559D0E0'

更多Jerry的原创文章,尽在:"汪子熙":