Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@sap/hdi
is a Node.js library that allows access to the SQL based API through Node.js. It provides access to the HDI-, Container-Group- and the Container-API.
Using the library:
Assuming that your npm registry is correctly configured and has access to SAP packages, simply running npm install --save @sap/hdi
will install the package and add it as a dependency to your package.json.
We recommend using version 2.0.0 or higher. V2 of the API brings access to the Container Group API, major refactoring of the HDI and Container API into separate components and lots of pre-defined classes to make working with the API easier.
Note that V2 is not backwards compatible to V1, code written with the old API will NOT run with new API. This documentation is for the V2 API.
All APIs require that the connected user has EXECUTE privileges for the corresponding SQL procedures and SELECT for all table types in SYS_DI (TT*).
Almost all methods are asynchronous and require a standard node-style callback, where the first parameter is any errors that occured and the second is the result.
This document only provides a really high-level and shallow overview of the API. For a more detailed, technical documentation, refer to the JSDoc. To generate the documentation, run npm install jsdoc
,npm install ink-docstrap
and then npm run documentation
. The documentation can then be found in the docs
folder.
Access to the _SYS_DI API is provided by the HDI
class. Access to this API requires HANA server version: 1.00.120 or newer. To work with the API, simply construct a new object, as can be seen in the following (ES6-based) example:
const { HDI } = require('@sap/hdi');
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
const credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
const hdi = new HDI(credentials, parameterSchema);
hdi.connect((error,result) => {
if(error){
throw error;
}
hdi.listLibraries(null,(error,result) => {
if(error){
throw error;
}
console.log(result);
})
})
To construct an access object, you need the credentials for the HANA system and the parameterSchema
. This schema will be used to create temporary tables to supply data to the underlying sql procedures.
The Container Group API provides access to an existing container group. In order to use the API, you might need to first grant the correct rights by using grantContainerGroupAPIPrivileges
of the HDI class.
To construct an access object, you need the credentials for the HANA system, the parameterSchema
and the name of the container group.
The Container API provides access to an existing container. In order to use the API, you might need to first grant the correct rights by using grantContainerAPIPrivileges
of the ContainerGroup class.
To construct an access object, you need the credentials for the HANA system, the parameterSchema
and the name of the container.
Example: Deploying files to a container
const { Container } = require("@sap/hdi");
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
const credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
const container = new Container(existingContainerName, credentials, parameterSchema)
const folderPath = '/';
const configPath = '/.hdiconfig';
const configContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}.hdiconfig`);
const tablePath = '/table1.hdbtable';
const tableContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}table1.hdbtable`);
const rolePath = '/role.hdbrole';
const roleContent = fs.createReadStream(`${__dirname}${path.sep}testdata${path.sep}role.hdbrole`);
const filesFoldersContent = [
new FolderWithContent(folderPath),
new FileWithContent(configPath, configContent),
new FileWithContent(tablePath, tableContent),
new FileWithContent(rolePath, roleContent)
];
const files = [new File(rolePath)];
// Connect to an existing container
container.connect((e,result) => {
if(e){
throw e;
return;
}
// Lock the container -> Optional but recommended
container.lock(0, null, function (e, result) {
if(e){
throw e;
return;
}
// Stage the files for deployment
container.write(filesFoldersContent, null, function (e, result) {
if(e){
throw e;
return;
}
// Check the container status, lists the staged files -> Optional
container.status(null, null, function (e, result) {
if(e){
throw e;
return;
}
// List the metadata for files/folders in the container file system -> Optional
container.list(paths, null, function (e, result) {
if(e){
throw e;
return;
}
// Deploy the files to the container. In this case, only the hdbrole file.
container.make(files, null, null, null, function (e, result) {
if(e){
throw e;
return;
}
// The file was successfully deployed.
});
});
});
});
});
});
Since most of the methods of the HDI, ContainerGroup and Container class are asynchronous, you need to use the provided sync
functionality to use them in xsjs code.
Be aware that this requires a version of xsjs that uses at least "@sap/fibrous": "0.5.0-0"
as a dependency. This fixes issues with sync
in combination with class methods.
If your version of xsjs is up to date in that regard, simply add sync
before your method calls. This
const { HDI } = require('@sap/hdi');
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
const credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
const hdi = new HDI(credentials, parameterSchema);
hdi.connect((error,result) => {
if(error){
throw error;
}
hdi.listLibraries(null,(error,result) => {
if(error){
throw error;
}
console.log(result);
})
})
turns into this:
var { HDI } = $.require('@sap/hdi');
#This credentials object will be directly passed to the hdb client. Any options accepted by the hdb client can be passed.
var credentials = {
host : <host>,
port : <port>,
user : <user>,
password: <password>
};
var hdi = new HDI(credentials, parameterSchema);
hdi.sync.connect();
var libraries = hdi.sync.listLibraries(null);
console.log(libraries);
FAQs
HDI client library for node.js
The npm package @sap/hdi receives a total of 91,443 weekly downloads. As such, @sap/hdi popularity was classified as popular.
We found that @sap/hdi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.