├── .github └── CODEOWNERS ├── hdb ├── @types │ ├── test.d.cts │ ├── test.d.ts │ ├── tests │ │ └── hdb.Test.d.ts │ ├── index.d.cts │ └── index.d.ts ├── tsconfig.json ├── .gitignore ├── package.json ├── tests │ └── hdb.Test.js ├── test.cjs ├── README.md ├── test.js ├── npm-shrinkwrap.json ├── index.js └── index.cjs ├── hdbext ├── @types │ ├── test.d.cts │ ├── test.d.ts │ ├── tests │ │ └── hdbext.Test.d.ts │ ├── index.d.cts │ └── index.d.ts ├── tsconfig.json ├── .gitignore ├── package.json ├── test.cjs ├── test.js ├── tests │ └── hdbext.Test.js ├── README.md ├── index.js ├── index.cjs └── npm-shrinkwrap.json ├── .gitignore ├── REUSE.toml ├── README.md ├── LICENSE └── LICENSES └── Apache-2.0.txt /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @jung-thomas 2 | -------------------------------------------------------------------------------- /hdb/@types/test.d.cts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /hdbext/@types/test.d.cts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /hdbext/@types/test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Test #1 3 | */ 4 | export function test1(): Promise; 5 | /** 6 | * Test #2 7 | */ 8 | export function test2(): Promise; 9 | /** 10 | * Test #3 11 | */ 12 | export function test3(): Promise; 13 | -------------------------------------------------------------------------------- /hdb/@types/test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Test #1 3 | */ 4 | export function test1(): Promise; 5 | /** 6 | * Test #2 7 | */ 8 | export function test2(): Promise; 9 | /** 10 | * Test #2.1 Current Schema 11 | */ 12 | export function test2_1(): Promise; 13 | /** 14 | * Test #2.2 15 | */ 16 | export function test2_2(): Promise; 17 | /** 18 | * Test #3 19 | */ 20 | export function test3(): Promise; 21 | -------------------------------------------------------------------------------- /hdb/@types/tests/hdb.Test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * hdb Await example 3 | * @param {string} [dbQuery] Database Query 4 | * @returns {Promise} HANA ResultSet Object 5 | */ 6 | export function example1(dbQuery?: string): Promise; 7 | /** 8 | * hdb procedure example with Callbacks 9 | * @param {string} [schema] Database Stored Procedure Schema 10 | * @param {string} [dbProcedure] Database Stored Procedure Name 11 | * @param {object} [inputParams] Database Stored Procedure Input Parameters 12 | * @returns {Promise} HANA ResultSet Object 13 | */ 14 | export function example2(schema?: string, dbProcedure?: string, inputParams?: object): Promise; 15 | -------------------------------------------------------------------------------- /hdbext/@types/tests/hdbext.Test.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * hdbext Await example 3 | * @param {string} [dbQuery] Database Query 4 | * @returns {Promise} HANA ResultSet Object 5 | */ 6 | export function example1(dbQuery?: string): Promise; 7 | /** 8 | * hdbext procedure example with Callbacks 9 | * @param {string} [schema] Database Stored Procedure Schema 10 | * @param {string} [dbProcedure] Database Stored Procedure Name 11 | * @param {object} [inputParams] Database Stored Procedure Input Parameters 12 | * @returns {Promise} HANA ResultSet Object 13 | */ 14 | export function example2(schema?: string, dbProcedure?: string, inputParams?: object): Promise; 15 | -------------------------------------------------------------------------------- /hdb/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // Change this to match your project 3 | "compilerOptions": { 4 | // Tells TypeScript to read JS files, as 5 | // normally they are ignored as source files 6 | "allowJs": true, 7 | // Generate d.ts files 8 | "declaration": true, 9 | // This compiler run should 10 | // only output d.ts files 11 | "emitDeclarationOnly": true, 12 | // Types should go into this directory. 13 | // Removing this would place the .d.ts files 14 | // next to the .js files 15 | "outDir": "@types", 16 | "rootDir": ".", 17 | "skipLibCheck": true, 18 | "lib": ["ES2020"], 19 | "target": "ES2020", 20 | "moduleResolution": "Node", 21 | "module": "es2020", 22 | "types": ["node","mocha"] 23 | } 24 | } -------------------------------------------------------------------------------- /hdbext/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // Change this to match your project 3 | "compilerOptions": { 4 | // Tells TypeScript to read JS files, as 5 | // normally they are ignored as source files 6 | "allowJs": true, 7 | // Generate d.ts files 8 | "declaration": true, 9 | // This compiler run should 10 | // only output d.ts files 11 | "emitDeclarationOnly": true, 12 | // Types should go into this directory. 13 | // Removing this would place the .d.ts files 14 | // next to the .js files 15 | "outDir": "@types", 16 | "rootDir": ".", 17 | "skipLibCheck": true, 18 | "lib": ["ES2020"], 19 | "target": "ES2020", 20 | "moduleResolution": "Node", 21 | "module": "es2020", 22 | "types": ["node", "mocha"] 23 | } 24 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | mta_archives/ 64 | default-*.json 65 | 66 | # dotenv environment variables file 67 | .env 68 | 69 | # Visual Studio Code 70 | .vscode 71 | -------------------------------------------------------------------------------- /hdbext/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | mta_archives/ 64 | default-*.json 65 | 66 | # dotenv environment variables file 67 | .env 68 | 69 | # Visual Studio Code 70 | .vscode 71 | -------------------------------------------------------------------------------- /hdb/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | mta_archives/ 64 | default-*.json 65 | 66 | # dotenv environment variables file 67 | .env 68 | 69 | # Visual Studio Code 70 | .vscode 71 | 72 | # added by cds 73 | .cdsrc-private.json 74 | -------------------------------------------------------------------------------- /hdbext/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sap-hdbext-promisfied", 3 | "version": "2.202510.0", 4 | "description": "Promise wrapper for @sap/hdbext", 5 | "main": "./index.cjs", 6 | "exports": { 7 | "./package.json": "./package.json", 8 | ".": [ 9 | { 10 | "import": "./index.js", 11 | "require": "./index.cjs" 12 | }, 13 | "./index.cjs" 14 | ] 15 | }, 16 | "type": "module", 17 | "module": "./index.js", 18 | "types": "./@types/index.d.ts", 19 | "keywords": [ 20 | "promise", 21 | "hdbext", 22 | "sap", 23 | "hana", 24 | "database" 25 | ], 26 | "author": "jung-thomas", 27 | "license": "Apache-2.0", 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/SAP-samples/hana-hdbext-promisfied-example" 31 | }, 32 | "dependencies": { 33 | "@sap/hdbext": "^8.1.9", 34 | "@sap/xsenv": "^6.0.0", 35 | "debug": "^4.4.3", 36 | "dotenv": "^17.2.3" 37 | }, 38 | "devDependencies": { 39 | "@types/node": "^24.9.2" 40 | }, 41 | "scripts": { 42 | "start": "node test", 43 | "types": "tsc --declaration --allowJs --emitDeclarationOnly --outDir @types", 44 | "prodinstall": "npm install --only=prod", 45 | "test": "mocha './tests/*.Test.js' --parallel --timeout 5000" 46 | }, 47 | "engines": { 48 | "node": ">=18.18.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hdb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sap-hdb-promisfied", 3 | "version": "2.202510.0", 4 | "description": "Promise wrapper for hdb without any dependency to @sap/hana-client", 5 | "main": "./index.cjs", 6 | "exports": { 7 | "./package.json": "./package.json", 8 | ".": [ 9 | { 10 | "import": "./index.js", 11 | "require": "./index.cjs" 12 | }, 13 | "./index.cjs" 14 | ] 15 | }, 16 | "type": "module", 17 | "module": "./index.js", 18 | "types": "./@types/index.d.ts", 19 | "keywords": [ 20 | "promise", 21 | "hdb", 22 | "sap", 23 | "hana", 24 | "database" 25 | ], 26 | "author": "jung-thomas", 27 | "license": "Apache-2.0", 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/SAP-samples/hana-hdbext-promisfied-example" 31 | }, 32 | "dependencies": { 33 | "@sap/xsenv": "^6.0.0", 34 | "debug": "4.4.3", 35 | "dotenv": "^17.2.3", 36 | "hdb": "2.26.1" 37 | }, 38 | "devDependencies": { 39 | "@types/debug": "^4.1.12", 40 | "@types/node": "^24.9.2", 41 | "@types/sap__xsenv": "^3.3.2" 42 | }, 43 | "scripts": { 44 | "start": "node test", 45 | "types": "tsc --declaration --allowJs --emitDeclarationOnly --outDir @types", 46 | "prodinstall": "npm install --only=prod", 47 | "test": "mocha './tests/*.Test.js' --parallel --timeout 5000" 48 | }, 49 | "engines": { 50 | "node": "^20.0.0 || ^22.0.0 || ^24.0.0" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hdbext/test.cjs: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | /** 3 | * Test #1 4 | */ 5 | async function test1() { 6 | // @ts-ignore 7 | const dbClass = require('./index.cjs') 8 | let envFile = dbClass.resolveEnv(null) 9 | dbClass.createConnectionFromEnv(envFile) 10 | .then(client => { 11 | let db = new dbClass(client) 12 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 13 | FROM "DUMMY"`) 14 | .then(statement => { 15 | db.statementExecPromisified(statement, []) 16 | .then(results => { 17 | console.table(results) 18 | }) 19 | .catch(err => { 20 | console.error(`ERROR: ${err.toString()}`) 21 | }) 22 | }) 23 | .catch(err => { 24 | console.error(`ERROR: ${err.toString()}`) 25 | }) 26 | }) 27 | .catch(err => { 28 | console.error(`ERROR: ${err.toString()}`) 29 | }) 30 | } 31 | test1() 32 | 33 | /** 34 | * Test #2 35 | */ 36 | async function test2() { 37 | try { 38 | // @ts-ignore 39 | const dbClass = require('./index.cjs') 40 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 41 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 42 | FROM "DUMMY"`) 43 | const results = await db.statementExecPromisified(statement, []) 44 | console.table(results) 45 | } catch (err) { 46 | console.error(`ERROR: ${err.toString()}`) 47 | } 48 | } 49 | test2() -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | SPDX-PackageName = "hana-hdbext-promisfied-example" 3 | SPDX-PackageSupplier = "Thomas Jung " 4 | SPDX-PackageDownloadLocation = "https://github.com/sap-samples/hana-hdbext-promisfied-example" 5 | SPDX-PackageComment = "The code in this project may include calls to APIs (“API Calls”) of\n SAP or third-party products or services developed outside of this project\n (“External Products”).\n “APIs” means application programming interfaces, as well as their respective\n specifications and implementing code that allows software to communicate with\n other software.\n API Calls to External Products are not licensed under the open source license\n that governs this project. The use of such API Calls and related External\n Products are subject to applicable additional agreements with the relevant\n provider of the External Products. In no event shall the open source license\n that governs this project grant any rights in or to any External Products,or\n alter, expand or supersede any terms of the applicable additional agreements.\n If you have a valid license agreement with SAP for the use of a particular SAP\n External Product, then you may make use of any API Calls included in this\n project’s code for that SAP External Product, subject to the terms of such\n license agreement. If you do not have a valid license agreement for the use of\n a particular SAP External Product, then you may only make use of any API Calls\n in this project for that SAP External Product for your internal, non-productive\n and non-commercial test and evaluation of such API Calls. Nothing herein grants\n you any rights to use or access any SAP External Product, or provide any third\n parties the right to use of access any SAP External Product, through API Calls." 6 | 7 | [[annotations]] 8 | path = "**" 9 | precedence = "aggregate" 10 | SPDX-FileCopyrightText = "2024 SAP SE or an SAP affiliate company and hana-hdbext-promisfied-example contributors" 11 | SPDX-License-Identifier = "Apache-2.0" 12 | -------------------------------------------------------------------------------- /hdbext/test.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import { performance, PerformanceObserver } from "perf_hooks" 3 | import dbClass from './index.js' 4 | import * as hdbext from '@sap/hdbext' 5 | const perfObserver = new PerformanceObserver((items) => { 6 | items.getEntries().forEach((entry) => { 7 | console.log(entry) 8 | }) 9 | }) 10 | perfObserver.observe({ entryTypes: ["measure"] }) 11 | 12 | /** 13 | * Test #1 14 | */ 15 | export async function test1() { 16 | performance.mark("1-start") 17 | let envFile = dbClass.resolveEnv(null) 18 | dbClass.createConnectionFromEnv(envFile) 19 | .then(client => { 20 | let db = new dbClass(client) 21 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 22 | FROM "DUMMY"`) 23 | .then(statement => { 24 | db.statementExecPromisified(statement, []) 25 | .then(results => { 26 | console.table(results) 27 | performance.mark("1-end") 28 | performance.measure("Test #1", "1-start", "1-end") 29 | }) 30 | .catch(err => { 31 | console.error(`ERROR: ${err.toString()}`) 32 | }) 33 | }) 34 | .catch(err => { 35 | console.error(`ERROR: ${err.toString()}`) 36 | }) 37 | }) 38 | .catch(err => { 39 | console.error(`ERROR: ${err.toString()}`) 40 | }) 41 | } 42 | 43 | 44 | /** 45 | * Test #2 46 | */ 47 | export async function test2() { 48 | performance.mark("2-start") 49 | try { 50 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 51 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 52 | FROM "DUMMY"`) 53 | const results = await db.statementExecPromisified(statement, []) 54 | console.table(results) 55 | performance.mark("2-end") 56 | performance.measure("Test #2", "2-start", "2-end") 57 | } catch (err) { 58 | console.error(`ERROR: ${err.toString()}`) 59 | } 60 | } 61 | 62 | 63 | 64 | /** 65 | * Test #3 66 | */ 67 | export async function test3() { 68 | performance.mark("3-start") 69 | try { 70 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 71 | let sp = await db.loadProcedurePromisified(hdbext, 'SYS', 'IS_VALID_PASSWORD') 72 | let output = await db.callProcedurePromisified(sp, {PASSWORD: "TEST"}) 73 | 74 | console.table(output) 75 | performance.mark("3-end") 76 | performance.measure("Test #3", "3-start", "3-end") 77 | } catch (err) { 78 | console.error(`ERROR: ${err.toString()}`) 79 | } 80 | } 81 | 82 | test3() 83 | test1() 84 | test2() 85 | test3() -------------------------------------------------------------------------------- /hdbext/tests/hdbext.Test.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | /** 3 | * @module hdbext - examples using sap-hdbext-promisfied 4 | */ 5 | 6 | 7 | import dbClass from '../index.js' 8 | /** @type {typeof import("@sap/hdbext")} */ 9 | import * as hdbext from '@sap/hdbext' 10 | import * as assert from 'assert' 11 | 12 | /** 13 | * hdbext Await example 14 | * @param {string} [dbQuery] Database Query 15 | * @returns {Promise} HANA ResultSet Object 16 | */ 17 | export async function example1(dbQuery) { 18 | try { 19 | let db = new dbClass(await dbClass.createConnectionFromEnv()) 20 | return await db.execSQL(dbQuery) 21 | } catch (error) { 22 | throw error 23 | } 24 | } 25 | 26 | 27 | /** 28 | * hdbext procedure example with Callbacks 29 | * @param {string} [schema] Database Stored Procedure Schema 30 | * @param {string} [dbProcedure] Database Stored Procedure Name 31 | * @param {object} [inputParams] Database Stored Procedure Input Parameters 32 | * @returns {Promise} HANA ResultSet Object 33 | */ 34 | export async function example2(schema, dbProcedure, inputParams) { 35 | try { 36 | let db = new dbClass(await dbClass.createConnectionFromEnv()) 37 | let sp = await db.loadProcedurePromisified(hdbext, schema, dbProcedure) 38 | return await db.callProcedurePromisified(sp, inputParams) 39 | } catch (error) { 40 | throw error 41 | } 42 | } 43 | 44 | describe('hdbext', () => { 45 | describe('Example with Await', () => { 46 | it('returns 10 records', async () => { 47 | let dbQuery = `SELECT SCHEMA_NAME, TABLE_NAME, COMMENTS FROM TABLES LIMIT 10` 48 | const results = await example1(dbQuery) 49 | assert.equal(results.length, 10) 50 | }) 51 | 52 | it('returns single record', async () => { 53 | let dbQuery = `SELECT CURRENT_USER, CURRENT_SCHEMA from DUMMY` 54 | const results = await example1(dbQuery) 55 | assert.equal(results.length, 1) 56 | }) 57 | 58 | it('throws error with target table not found', () => { 59 | let dbQuery = `SELECT CURRENT_USER, CURRENT_SCHEMA from DUMMY_DUMB` 60 | assert.rejects(async () => { await example1(dbQuery) }, Error) 61 | }) 62 | }) 63 | 64 | 65 | describe('Example Stored Procedure with Await', () => { 66 | it('Password is too short - Error Code 412', async () => { 67 | let result = await example2('SYS', 'IS_VALID_PASSWORD', { PASSWORD: "TEST" }) 68 | assert.equal(result.outputScalar.ERROR_CODE, 412) 69 | }) 70 | 71 | it('Password is good - Error Code 412', async () => { 72 | let result = await example2('SYS', 'IS_VALID_PASSWORD', { PASSWORD: "TESTtest1234" }) 73 | assert.equal(result.outputScalar.ERROR_CODE, 0) 74 | }) 75 | 76 | it('throws error with Stored Procedure not found', async () => { 77 | assert.rejects(async () => { await example2('SYS', 'IS_VALID_PASSWORD_NOT_A_PROC', { PASSWORD: "TESTtest1234" }) }, Error) 78 | }) 79 | 80 | }) 81 | }) -------------------------------------------------------------------------------- /hdb/tests/hdb.Test.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | // @ts-check 4 | /** 5 | * @module hdb - examples using sap-hdb-promisfied 6 | */ 7 | 8 | import dbClass from '../index.js' 9 | import * as assert from 'assert' 10 | 11 | /** 12 | * hdb Await example 13 | * @param {string} [dbQuery] Database Query 14 | * @returns {Promise} HANA ResultSet Object 15 | */ 16 | export async function example1(dbQuery) { 17 | try { 18 | let db = new dbClass(await dbClass.createConnectionFromEnv()) 19 | let result = await db.execSQL(dbQuery) 20 | db.destroyClient() 21 | return result 22 | } catch (error) { 23 | throw error 24 | } 25 | } 26 | 27 | 28 | /** 29 | * hdb procedure example with Callbacks 30 | * @param {string} [schema] Database Stored Procedure Schema 31 | * @param {string} [dbProcedure] Database Stored Procedure Name 32 | * @param {object} [inputParams] Database Stored Procedure Input Parameters 33 | * @returns {Promise} HANA ResultSet Object 34 | */ 35 | export async function example2(schema, dbProcedure, inputParams) { 36 | try { 37 | let db = new dbClass(await dbClass.createConnectionFromEnv()) 38 | let sp = await db.loadProcedurePromisified(schema, dbProcedure) 39 | let result = await db.callProcedurePromisified(sp, inputParams) 40 | db.destroyClient() 41 | return result 42 | } catch (error) { 43 | throw error 44 | } 45 | } 46 | 47 | 48 | describe('hdb', () => { 49 | describe('Example with Await', () => { 50 | it('returns 10 records', async () => { 51 | let dbQuery = `SELECT SCHEMA_NAME, TABLE_NAME, COMMENTS FROM TABLES LIMIT 10` 52 | const results = await example1(dbQuery) 53 | assert.equal(results.length, 10) 54 | }) 55 | 56 | it('returns single record', async () => { 57 | let dbQuery = `SELECT CURRENT_USER, CURRENT_SCHEMA from DUMMY` 58 | const results = await example1(dbQuery) 59 | assert.equal(results.length, 1) 60 | }) 61 | 62 | it('throws error with target table not found', () => { 63 | let dbQuery = `SELECT CURRENT_USER, CURRENT_SCHEMA from DUMMY_DUMB` 64 | assert.rejects(async () => { await example1(dbQuery) }, Error) 65 | }) 66 | }) 67 | 68 | 69 | describe('Example Stored Procedure with Await', () => { 70 | it('Password is too short - Error Code 412', async () => { 71 | let result = await example2('SYS', 'IS_VALID_PASSWORD', { PASSWORD: "TEST" }) 72 | assert.equal(result.outputScalar.ERROR_CODE, 412) 73 | }) 74 | 75 | it('Password is good - Error Code 412', async () => { 76 | let result = await example2('SYS', 'IS_VALID_PASSWORD', { PASSWORD: "TESTtest1234" }) 77 | assert.equal(result.outputScalar.ERROR_CODE, 0) 78 | }) 79 | 80 | it('throws error with Stored Procedure not found', async () => { 81 | assert.rejects(async () => { await example2('SYS', 'IS_VALID_PASSWORD_NOT_A_PROC', { PASSWORD: "TESTtest1234" }) }, Error) 82 | }) 83 | 84 | }) 85 | }) -------------------------------------------------------------------------------- /hdbext/@types/index.d.cts: -------------------------------------------------------------------------------- 1 | /// 2 | export = exports; 3 | declare class exports { 4 | /** 5 | * Create Database Connection From Environment 6 | * @param {string} [envFile] - Override with a specific Environment File 7 | * @returns {Promise} - HANA Client instance of sap/hdbext 8 | */ 9 | static createConnectionFromEnv(envFile?: string): Promise; 10 | /** 11 | * Create Database Connection with specific connection options in format expected by sap/hdbext 12 | * @param {any} options - Input options or parameters 13 | * @returns {Promise} - HANA Client instance of sap/hdbext 14 | */ 15 | static createConnection(options: any): Promise; 16 | /** 17 | * Determine default env file name and location 18 | * @param {any} options - Input options or parameters 19 | * @returns string - default env file name and path 20 | */ 21 | static resolveEnv(options: any): string; 22 | /** 23 | * Calculation the current schema name 24 | * @param {any} options - Input options or parameters 25 | * @param {any} db - HANA Client instance of sap/hdbext 26 | * @returns {Promise} - Schema 27 | */ 28 | static schemaCalc(options: any, db: any): Promise; 29 | /** 30 | * Calculation Object name from wildcards 31 | * @param {string} name - DB object name 32 | * @returns {string} - final object name 33 | */ 34 | static objectName(name: string): string; 35 | /** 36 | * @constructor 37 | * @param {object} client - HANA DB Client instance of type sap/hdbext 38 | */ 39 | constructor(client: object); 40 | client: any; 41 | util: typeof import("util"); 42 | /** 43 | * Prepare database statement 44 | * @param {string} query - database query 45 | * @returns {any} - prepared statement object 46 | */ 47 | preparePromisified(query: string): any; 48 | /** 49 | * Execute DB Statement in Batch 50 | * @param {any} statement - prepared statement object 51 | * @param {any} parameters - query parameters 52 | * @returns {Promise} - resultset 53 | */ 54 | statementExecBatchPromisified(statement: any, parameters: any): Promise; 55 | /** 56 | * Execute DB Statement 57 | * @param {any} statement - prepared statement object 58 | * @param {any} parameters - query parameters 59 | * @returns {Promise} - resultset 60 | */ 61 | statementExecPromisified(statement: any, parameters: any): Promise; 62 | /** 63 | * Load stored procedure and return proxy function 64 | * @param {any} hdbext - instance of db client sap/hdbext 65 | * @param {string} schema - Schema name can be null 66 | * @param {string} procedure - DB procedure name 67 | * @returns {Promise} - proxy function 68 | */ 69 | loadProcedurePromisified(hdbext: any, schema: string, procedure: string): Promise; 70 | /** 71 | * Execute single SQL Statement and directly return result set 72 | * @param {string} sql - SQL Statement 73 | * @returns {Promise} - result set object 74 | */ 75 | execSQL(sql: string): Promise; 76 | /** 77 | * Call Database Procedure 78 | * @param {function} storedProc - stored procedure proxy function 79 | * @param {any} inputParams - input parameters for the stored procedure 80 | * @returns 81 | */ 82 | callProcedurePromisified(storedProc: Function, inputParams: any): Promise; 83 | } 84 | -------------------------------------------------------------------------------- /hdbext/@types/index.d.ts: -------------------------------------------------------------------------------- 1 | export const debug: any; 2 | /** 3 | * @module sap-hdbext-promisfied - promises version of sap/hdbext 4 | */ 5 | export default class dbClass { 6 | /** 7 | * Create Database Connection From Environment 8 | * @param {string} [envFile] - Override with a specific Environment File 9 | * @returns {Promise} - HANA Client instance of sap/hdbext 10 | */ 11 | static createConnectionFromEnv(envFile?: string): Promise; 12 | /** 13 | * Create Database Connection with specific connection options in format expected by sap/hdbext 14 | * @param {any} options - Input options or parameters 15 | * @returns {Promise} - HANA Client instance of sap/hdbext 16 | */ 17 | static createConnection(options: any): Promise; 18 | /** 19 | * Determine default env file name and location 20 | * @param {any} options - Input options or parameters 21 | * @returns string - default env file name and path 22 | */ 23 | static resolveEnv(options: any): string; 24 | /** 25 | * Calculation the current schema name 26 | * @param {any} options - Input options or parameters 27 | * @param {any} db - HANA Client instance of sap/hdbext 28 | * @returns {Promise} - Schema 29 | */ 30 | static schemaCalc(options: any, db: any): Promise; 31 | /** 32 | * Calculation Object name from wildcards 33 | * @param {string} name - DB object name 34 | * @returns {string} - final object name 35 | */ 36 | static objectName(name: string): string; 37 | /** 38 | * @constructor 39 | * @param {object} client - HANA DB Client instance of type sap/hdbext 40 | */ 41 | constructor(client: object); 42 | client: any; 43 | /** 44 | * Prepare database statement 45 | * @param {string} query - database query 46 | * @returns {any} - prepared statement object 47 | */ 48 | preparePromisified(query: string): any; 49 | /** 50 | * Execute DB Statement in Batch 51 | * @param {any} statement - prepared statement object 52 | * @param {any} parameters - query parameters 53 | * @returns {Promise} - resultset 54 | */ 55 | statementExecBatchPromisified(statement: any, parameters: any): Promise; 56 | /** 57 | * Execute DB Statement 58 | * @param {any} statement - prepared statement object 59 | * @param {any} parameters - query parameters 60 | * @returns {Promise} - resultset 61 | */ 62 | statementExecPromisified(statement: any, parameters: any): Promise; 63 | /** 64 | * Load stored procedure and return proxy function 65 | * @param {any} hdbext - instance of db client sap/hdbext 66 | * @param {string} schema - Schema name can be null 67 | * @param {string} procedure - DB procedure name 68 | * @returns {Promise} - proxy function 69 | */ 70 | loadProcedurePromisified(hdbext: any, schema: string, procedure: string): Promise; 71 | /** 72 | * Execute single SQL Statement and directly return result set 73 | * @param {string} sql - SQL Statement 74 | * @returns {Promise} - result set object 75 | */ 76 | execSQL(sql: string): Promise; 77 | /** 78 | * Call Database Procedure 79 | * @param {function} storedProc - stored procedure proxy function 80 | * @param {any} inputParams - input parameters for the stored procedure 81 | * @returns 82 | */ 83 | callProcedurePromisified(storedProc: Function, inputParams: any): Promise; 84 | } 85 | -------------------------------------------------------------------------------- /hdb/@types/index.d.cts: -------------------------------------------------------------------------------- 1 | /// 2 | export = exports; 3 | declare class exports { 4 | /** 5 | * Create Database Connection From Environment 6 | * @param {string} [envFile] - Override with a specific Environment File 7 | * @returns {Promise} - HANA Client instance of hdb 8 | */ 9 | static createConnectionFromEnv(envFile?: string): Promise; 10 | /** 11 | * Create Database Connection with specific connection options in format expected by hdb 12 | * @param {any} options - Input options or parameters 13 | * @returns {Promise} - HANA Client instance of hdb 14 | */ 15 | static createConnection(options: any): Promise; 16 | /** 17 | * Set default schema based upon connection parameters 18 | * @param {any} options - Input options or parameters 19 | * @param {any} client - HANA Client instance of hdb 20 | */ 21 | static setSchema(options: any, client: any): Promise; 22 | /** 23 | * Determine default env file name and location 24 | * @param {any} options - Input options or parameters 25 | * @returns string - default env file name and path 26 | */ 27 | static resolveEnv(options: any): string; 28 | /** 29 | * Calculation Object name from wildcards 30 | * @param {string} name - DB object name 31 | * @returns {string} - final object name 32 | */ 33 | static objectName(name: string): string; 34 | /** 35 | * @constructor 36 | * @param {object} client - HANA DB Client instance of type hdb 37 | */ 38 | constructor(client: object); 39 | /** 40 | * Calculation the current schema name 41 | * @param {any} options - Input options or parameters 42 | * @param {any} db - HANA Client instance of hdb 43 | * @returns {Promise} - Schema 44 | */ 45 | schemaCalc(options: any, db: any): Promise; 46 | /** 47 | * Load Metadata of a Stored Procedure 48 | * @param {any} db - HANA Client instance of hdb 49 | * @param {any} procInfo - Details of Schema/Stored Procedure to Lookup 50 | * @returns {Promise} - Result Set 51 | */ 52 | fetchSPMetadata(db: any, procInfo: any): Promise; 53 | client: any; 54 | util: typeof import("util"); 55 | /** 56 | * Destroy Client 57 | */ 58 | destroyClient(): void; 59 | /** 60 | * Destroy Client 61 | */ 62 | validateClient(): boolean; 63 | /** 64 | * Prepare database statement 65 | * @param {string} query - database query 66 | * @returns {any} - prepared statement object 67 | */ 68 | preparePromisified(query: string): any; 69 | /** 70 | * Execute DB Statement in Batch 71 | * @param {any} statement - prepared statement object 72 | * @param {any} parameters - query parameters 73 | * @returns {Promise} - resultset 74 | */ 75 | statementExecBatchPromisified(statement: any, parameters: any): Promise; 76 | /** 77 | * Execute DB Statement 78 | * @param {any} statement - prepared statement object 79 | * @param {any} parameters - query parameters 80 | * @returns {Promise} - resultset 81 | */ 82 | statementExecPromisified(statement: any, parameters: any): Promise; 83 | /** 84 | * Load stored procedure and return proxy function 85 | * @param {string} schema - Schema name can be null 86 | * @param {string} procedure - DB procedure name 87 | * @returns {Promise} - proxy function 88 | */ 89 | loadProcedurePromisified(schema: string, procedure: string): Promise; 90 | /** 91 | * Execute single SQL Statement and directly return result set 92 | * @param {string} sql - SQL Statement 93 | * @returns {Promise} - result set object 94 | */ 95 | execSQL(sql: string): Promise; 96 | /** 97 | * Call Database Procedure 98 | * @param {any} storedProc - stored procedure proxy function 99 | * @param {any} inputParams - input parameters for the stored procedure 100 | * @returns 101 | */ 102 | callProcedurePromisified(storedProc: any, inputParams: any): Promise; 103 | } 104 | -------------------------------------------------------------------------------- /hdb/@types/index.d.ts: -------------------------------------------------------------------------------- 1 | export const debug: any; 2 | /** 3 | * @module sap-hdb-promisfied - promises version of hdb 4 | */ 5 | export default class dbClass { 6 | /** 7 | * Create Database Connection From Environment 8 | * @param {string} [envFile] - Override with a specific Environment File 9 | * @returns {Promise} - HANA Client instance of hdb 10 | */ 11 | static createConnectionFromEnv(envFile?: string): Promise; 12 | /** 13 | * Create Database Connection with specific connection options in format expected by hdb 14 | * @param {any} options - Input options or parameters 15 | * @returns {Promise} - HANA Client instance of hdb 16 | */ 17 | static createConnection(options: any): Promise; 18 | /** 19 | * Set default schema based upon connection parameters 20 | * @param {any} options - Input options or parameters 21 | * @param {any} client - HANA Client instance of hdb 22 | */ 23 | static setSchema(options: any, client: any): Promise; 24 | /** 25 | * Determine default env file name and location 26 | * @param {any} options - Input options or parameters 27 | * @returns string - default env file name and path 28 | */ 29 | static resolveEnv(options: any): string; 30 | /** 31 | * Calculation the current schema name 32 | * @param {any} options - Input options or parameters 33 | * @param {any} db - HANA Client instance of hdb 34 | * @returns {Promise} - Schema 35 | */ 36 | static schemaCalc(options: any, db: any): Promise; 37 | /** 38 | * Load Metadata of a Stored Procedure 39 | * @param {any} db - HANA Client instance of hdb 40 | * @param {any} procInfo - Details of Schema/Stored Procedure to Lookup 41 | * @returns {Promise} - Result Set 42 | */ 43 | static fetchSPMetadata(db: any, procInfo: any): Promise; 44 | /** 45 | * Calculation Object name from wildcards 46 | * @param {string} name - DB object name 47 | * @returns {string} - final object name 48 | */ 49 | static objectName(name: string): string; 50 | /** 51 | * @constructor 52 | * @param {object} client - HANA DB Client instance of type hdb 53 | */ 54 | constructor(client: object); 55 | client: any; 56 | /** 57 | * Destroy Client 58 | */ 59 | destroyClient(): void; 60 | /** 61 | * Destroy Client 62 | */ 63 | validateClient(): boolean; 64 | /** 65 | * Prepare database statement 66 | * @param {string} query - database query 67 | * @returns {any} - prepared statement object 68 | */ 69 | preparePromisified(query: string): any; 70 | /** 71 | * Execute DB Statement in Batch 72 | * @param {any} statement - prepared statement object 73 | * @param {any} parameters - query parameters 74 | * @returns {Promise} - resultset 75 | */ 76 | statementExecBatchPromisified(statement: any, parameters: any): Promise; 77 | /** 78 | * Execute DB Statement 79 | * @param {any} statement - prepared statement object 80 | * @param {any} parameters - query parameters 81 | * @returns {Promise} - resultset 82 | */ 83 | statementExecPromisified(statement: any, parameters: any): Promise; 84 | /** 85 | * Load stored procedure and return proxy function 86 | * @param {string} schema - Schema name can be null 87 | * @param {string} procedure - DB procedure name 88 | * @returns {Promise} - proxy function 89 | */ 90 | loadProcedurePromisified(schema: string, procedure: string): Promise; 91 | /** 92 | * Execute single SQL Statement and directly return result set 93 | * @param {string} sql - SQL Statement 94 | * @returns {Promise} - result set object 95 | */ 96 | execSQL(sql: string): Promise; 97 | /** 98 | * Call Database Procedure 99 | * @param {any} storedProc - stored procedure proxy function 100 | * @param {any} inputParams - input parameters for the stored procedure 101 | * @returns 102 | */ 103 | callProcedurePromisified(storedProc: any, inputParams: any): Promise; 104 | } 105 | -------------------------------------------------------------------------------- /hdb/test.cjs: -------------------------------------------------------------------------------- 1 | const dbClass = require('./index.cjs') 2 | const xsenv = require("@sap/xsenv") 3 | 4 | /** 5 | * Test #1 6 | */ 7 | async function test1() { 8 | 9 | let envFile = dbClass.resolveEnv(null) 10 | dbClass.createConnectionFromEnv(envFile) 11 | .then((/** @type {any} */ client) => { 12 | let db = new dbClass(client) 13 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 14 | FROM "DUMMY"`) 15 | .then((/** @type {any} */ statement) => { 16 | db.statementExecPromisified(statement, []) 17 | .then(/** @type {any} */ (/** @type {any} */ results) => { 18 | console.table(results) 19 | db.destroyClient() 20 | }) 21 | .catch(/** @type {any} */ (/** @type {{ toString: () => any; }} */ err) => { 22 | console.error(`ERROR: ${err.toString()}`) 23 | }) 24 | }) 25 | .catch((/** @type {{ toString: () => any; }} */ err) => { 26 | console.error(`ERROR: ${err.toString()}`) 27 | }) 28 | }) 29 | .catch((/** @type {{ toString: () => any; }} */ err) => { 30 | console.error(`ERROR: ${err.toString()}`) 31 | }) 32 | } 33 | //test1() 34 | 35 | /** 36 | * Test #2 37 | */ 38 | async function test2() { 39 | try { 40 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 41 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 42 | FROM "DUMMY"`) 43 | const results = await db.statementExecPromisified(statement, []) 44 | console.table(results) 45 | db.destroyClient() 46 | } catch (/** @type {any} */ err) { 47 | console.error(`ERROR: ${err.toString()}`) 48 | } 49 | } 50 | //test2() 51 | 52 | /** 53 | * Test #2.1 Current Schema 54 | */ 55 | async function test2_1() { 56 | try { 57 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 58 | let schema = await db.schemaCalc({schema: '**CURRENT_SCHEMA**'}, db) 59 | console.log(`Current Schema: ${schema}`) 60 | db.destroyClient() 61 | } catch (/** @type {any} */ err) { 62 | console.error(`ERROR: ${err.toString()}`) 63 | } 64 | } 65 | //test2_1() 66 | 67 | /** 68 | * Test #2.2 69 | */ 70 | async function test2_2() { 71 | try { 72 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 73 | const statement = await db.preparePromisified(`select top 50 SCHEMA_NAME, TABLE_NAME from TABLES WHERE SCHEMA_NAME = ?`) 74 | const results = await db.statementExecPromisified(statement, ['SYS']) 75 | console.table(results) 76 | db.destroyClient() 77 | } catch (/** @type {any} */ err) { 78 | console.error(`ERROR: ${err.toString()}`) 79 | } 80 | } 81 | //test2_2() 82 | 83 | /** 84 | * Test #3 85 | */ 86 | async function test3() { 87 | try { 88 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 89 | let sp = await db.loadProcedurePromisified('SYS', 'IS_VALID_PASSWORD') 90 | let output = await db.callProcedurePromisified(sp, {PASSWORD: "TEST"}) 91 | 92 | console.table(output) 93 | db.destroyClient() 94 | } catch (/** @type {any} */ err) { 95 | console.error(`ERROR: ${err.toString()}`) 96 | } 97 | } 98 | //test3() 99 | 100 | 101 | 102 | async function testUps() { 103 | try { 104 | xsenv.loadEnv() 105 | let userProvidedHanaEnv = xsenv.serviceCredentials({ label: 'user-provided' }) 106 | //console.log("credentials for user provided") 107 | //console.log(userProvidedHanaEnv) 108 | let connectionDetails = { hana: userProvidedHanaEnv } 109 | //console.log(connectionDetails.hana) 110 | //let db = new dbClass(await dbClass.createConnection(dbClass.resolveEnv())); 111 | const db = new dbClass(await dbClass.createConnection(connectionDetails)) 112 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 113 | FROM "DUMMY"`) 114 | const results = await db.statementExecPromisified(statement, []) 115 | console.table(results) 116 | db.destroyClient() 117 | } catch (/** @type {any} */ err) { 118 | console.error(`ERROR: ${err.toString()}`) 119 | } 120 | 121 | } 122 | test1() 123 | test2_1() 124 | test2_2() 125 | test3() 126 | testUps() -------------------------------------------------------------------------------- /hdb/README.md: -------------------------------------------------------------------------------- 1 | # Promisfied Wrapper around hdb 2 | 3 | [![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/hana-hdbext-promisfied-example)](https://api.reuse.software/info/github.com/SAP-samples/hana-hdbext-promisfied-example) 4 | 5 | ## Description 6 | 7 | With the standard hdb module you use nested events and callbacks like this: 8 | 9 | ```JavaScript 10 | let client = req.db; 11 | client.prepare( 12 | `SELECT SESSION_USER, CURRENT_SCHEMA 13 | FROM "DUMMY"`, 14 | (err, statement) => { 15 | if (err) { 16 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`); 17 | } 18 | statement.exec([], (err, results) => { 19 | if (err) { 20 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`); 21 | } else { 22 | var result = JSON.stringify({ 23 | Objects: results 24 | }); 25 | return res.type("application/json").status(200).send(result); 26 | } 27 | }); 28 | return null; 29 | }); 30 | ``` 31 | 32 | However this module wraps the major features of hdb module in a ES6 class and returns promises. Therefore you could re-write the above block using the easier to read and maintain promise based approach. You just pass in an instance of the HANA Client @sap/hdbext module. In this example its a typical example that gets the HANA client as Express Middelware (req.db): 33 | 34 | ```JavaScript 35 | const dbClass = require("sap-hdb-promisfied") 36 | let db = new dbClass(req.db) 37 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 38 | FROM "DUMMY"`) 39 | .then(statement => { 40 | db.statementExecPromisified(statement, []) 41 | .then(results => { 42 | let result = JSON.stringify({ 43 | Objects: results 44 | }) 45 | return res.type("application/json").status(200).send(result) 46 | }) 47 | .catch(err => { 48 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`) 49 | }) 50 | }) 51 | .catch(err => { 52 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`) 53 | }) 54 | ``` 55 | 56 | Or better yet if you are running Node.js 8.x or higher you can use the new AWAIT feature and the code is even more streamlined: 57 | 58 | ```JavaScript 59 | try { 60 | const dbClass = require("sap-hdb-promisfied") 61 | let db = new dbClass(req.db); 62 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 63 | FROM "DUMMY"`) 64 | const results = await db.statementExecPromisified(statement, []) 65 | let result = JSON.stringify({ 66 | Objects: results 67 | }) 68 | return res.type("application/json").status(200).send(result) 69 | } catch (e) { 70 | return res.type("text/plain").status(500).send(`ERROR: ${e.toString()}`) 71 | } 72 | ``` 73 | 74 | There are even static helpers to load the HANA connection information from the environment (or local testing file like default-env.json or .env) and create the HANA client for you. We can adjust the above example for such a scenario: 75 | 76 | ```JavaScript 77 | try { 78 | import dbClass from 'sap-hdb-promisfied' 79 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 80 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 81 | FROM "DUMMY"`) 82 | const results = await db.statementExecPromisified(statement, []) 83 | console.table(results) 84 | db.destroyClient() 85 | } catch (/** @type {any} */ err) { 86 | console.error(`ERROR: ${err.toString()}`) 87 | } 88 | ``` 89 | 90 | ### Methods 91 | 92 | The following hdb functions are exposed as promise-based methods 93 | 94 | ```JavaScript 95 | prepare = preparePromisified(query) 96 | statement.exec = statementExecPromisified(statement, parameters) 97 | loadProcedure = loadProcedurePromisified(hdbext, schema, procedure) 98 | storedProc = callProcedurePromisified(storedProc, inputParams) 99 | ``` 100 | 101 | We also have the simplified helper method to both prepare and execute a simple statement via one command: 102 | 103 | ```JavaScript 104 | execSQL(sql) 105 | ``` 106 | 107 | And finally there are static helpers 108 | 109 | ```JavaScript 110 | createConnectionFromEnv(envFile) 111 | createConnection(options) 112 | resolveEnv(options) 113 | schemaCalc(options, db) 114 | objectName(name) 115 | ``` 116 | 117 | ## Requirements / Download and Installation 118 | 119 | * Install any supported version of Node.js on your development machine [https://nodejs.org/en/download/](https://nodejs.org/en/download/) 120 | 121 | * Install the code sample as a reusable Node.js module 122 | 123 | ```shell 124 | npm install -g sap-hdb-promisfied 125 | ``` 126 | 127 | Or you can leverage this module by just listing as requirement in your own project's package.json. 128 | 129 | Finally you can clone the repository from [https://github.com/SAP-samples/hana-hdbext-promisified-example](https://github.com/SAP-samples/hana-hdbext-promisfied-example) to study the source content and view the consumption examples (test.js) 130 | 131 | ## Known Issues 132 | 133 | None 134 | 135 | ## How to obtain support 136 | 137 | This project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases. 138 | 139 | ## License 140 | 141 | Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](../LICENSES/Apache-2.0.txt) file. 142 | -------------------------------------------------------------------------------- /hdbext/README.md: -------------------------------------------------------------------------------- 1 | # Promisfied Wrapper around @sap/hdbext 2 | 3 | [![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/hana-hdbext-promisfied-example)](https://api.reuse.software/info/github.com/SAP-samples/hana-hdbext-promisfied-example) 4 | 5 | ## Description 6 | 7 | With the standard @sap/hdbext you use nested events and callbacks like this: 8 | 9 | ```JavaScript 10 | let client = req.db; 11 | client.prepare( 12 | `SELECT SESSION_USER, CURRENT_SCHEMA 13 | FROM "DUMMY"`, 14 | (err, statement) => { 15 | if (err) { 16 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`); 17 | } 18 | statement.exec([], (err, results) => { 19 | if (err) { 20 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`); 21 | } else { 22 | var result = JSON.stringify({ 23 | Objects: results 24 | }); 25 | return res.type("application/json").status(200).send(result); 26 | } 27 | }); 28 | return null; 29 | }); 30 | ``` 31 | 32 | However this module wraps the major features of @sap/hdbext in a ES6 class and returns promises. Therefore you could re-write the above block using the easier to read and maintain promise based approach. You just pass in an instance of the HANA Client @sap/hdbext module. In this example its a typical example that gets the HANA client as Express Middelware (req.db): 33 | 34 | ```JavaScript 35 | const dbClass = require("sap-hdbext-promisfied") 36 | let db = new dbClass(req.db) 37 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 38 | FROM "DUMMY"`) 39 | .then(statement => { 40 | db.statementExecPromisified(statement, []) 41 | .then(results => { 42 | let result = JSON.stringify({ 43 | Objects: results 44 | }) 45 | return res.type("application/json").status(200).send(result) 46 | }) 47 | .catch(err => { 48 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`) 49 | }) 50 | }) 51 | .catch(err => { 52 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`) 53 | }) 54 | ``` 55 | 56 | Or better yet if you are running Node.js 8.x or higher you can use the new AWAIT feature and the code is even more streamlined: 57 | 58 | ```JavaScript 59 | try { 60 | const dbClass = require("sap-hdbext-promisfied") 61 | let db = new dbClass(req.db); 62 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 63 | FROM "DUMMY"`) 64 | const results = await db.statementExecPromisified(statement, []) 65 | let result = JSON.stringify({ 66 | Objects: results 67 | }) 68 | return res.type("application/json").status(200).send(result) 69 | } catch (e) { 70 | return res.type("text/plain").status(500).send(`ERROR: ${e.toString()}`) 71 | } 72 | ``` 73 | 74 | There are even static helpers to load the HANA connection information from the environment (or local testing file like default-env.json or .env) and create the HANA client for you. We can adjust the above example for such a scenario: 75 | 76 | ```JavaScript 77 | try { 78 | const dbClass = require("sap-hdbext-promisfied") 79 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 80 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 81 | FROM "DUMMY"`) 82 | const results = await db.statementExecPromisified(statement, []) 83 | console.table(results) 84 | } catch (e) { 85 | console.error(`ERROR: ${err.toString()}`) 86 | } 87 | ``` 88 | 89 | ### Methods 90 | 91 | The following @sap/hdbext functions are exposed as promise-based methods 92 | 93 | ```JavaScript 94 | prepare = preparePromisified(query) 95 | statement.exec = statementExecPromisified(statement, parameters) 96 | loadProcedure = loadProcedurePromisified(hdbext, schema, procedure) 97 | storedProc = callProcedurePromisified(storedProc, inputParams) 98 | ``` 99 | 100 | We also have the simplified helper method to both prepare and execute a simple statement via one command: 101 | 102 | ```JavaScript 103 | execSQL(sql) 104 | ``` 105 | 106 | And finally there are static helpers 107 | 108 | ```JavaScript 109 | createConnectionFromEnv(envFile) 110 | createConnection(options) 111 | resolveEnv(options) 112 | schemaCalc(options, db) 113 | objectName(name) 114 | ``` 115 | 116 | ## Requirements / Download and Installation 117 | 118 | * Install Node.js version 12.x or 14.x on your development machine [https://nodejs.org/en/download/](https://nodejs.org/en/download/) 119 | 120 | * @sap Node.js packages have moved from https://npm.sap.com to the default registry https://registry.npmjs.org. As future versions of @sap modules are going to be published only there, please make sure to adjust your registry with: 121 | 122 | ```shell 123 | npm config delete @sap:registry 124 | ``` 125 | 126 | * Install the code sample as a reusable Node.js module 127 | 128 | ```shell 129 | npm install -g sap-hdbext-promisfied 130 | ``` 131 | 132 | Or you can leverage this module by just listing as requirement in your own project's package.json. 133 | 134 | Finally you can clone the repository from [https://github.com/SAP-samples/hana-hdbext-promisified-example](https://github.com/SAP-samples/hana-hdbext-promisfied-example) to study the source content and view the consumption examples (test.js) 135 | 136 | ## Known Issues 137 | 138 | None 139 | 140 | ## How to obtain support 141 | 142 | This project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases. 143 | 144 | ## License 145 | 146 | Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](../LICENSES/Apache-2.0.txt) file. 147 | 148 | -------------------------------------------------------------------------------- /hdb/test.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import { performance, PerformanceObserver } from "perf_hooks" 3 | import dbClass from './index.js' 4 | import * as xsenv from '@sap/xsenv' 5 | 6 | //import * as hdbext from '@sap/hdbext' 7 | const perfObserver = new PerformanceObserver((items) => { 8 | items.getEntries().forEach((entry) => { 9 | console.log(entry) 10 | }) 11 | }) 12 | perfObserver.observe({ entryTypes: ["measure"] }) 13 | 14 | /** 15 | * Test #1 16 | */ 17 | export async function test1() { 18 | performance.mark("1-start") 19 | let envFile = dbClass.resolveEnv(null) 20 | dbClass.createConnectionFromEnv(envFile) 21 | .then((/** @type {any} */ client) => { 22 | let db = new dbClass(client) 23 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 24 | FROM "DUMMY"`) 25 | .then((/** @type {any} */ statement) => { 26 | db.statementExecPromisified(statement, []) 27 | .then(/** @type {any} */(/** @type {any} */ results) => { 28 | console.table(results) 29 | db.destroyClient() 30 | performance.mark("1-end") 31 | performance.measure("Test #1", "1-start", "1-end") 32 | }) 33 | .catch(/** @type {any} */(/** @type {{ toString: () => any; }} */ err) => { 34 | console.error(`ERROR: ${err.toString()}`) 35 | }) 36 | }) 37 | .catch((/** @type {{ toString: () => any; }} */ err) => { 38 | console.error(`ERROR: ${err.toString()}`) 39 | }) 40 | }) 41 | .catch((/** @type {{ toString: () => any; }} */ err) => { 42 | console.error(`ERROR: ${err.toString()}`) 43 | }) 44 | } 45 | 46 | 47 | /** 48 | * Test #2 49 | */ 50 | export async function test2() { 51 | performance.mark("2-start") 52 | try { 53 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 54 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 55 | FROM "DUMMY"`) 56 | const results = await db.statementExecPromisified(statement, []) 57 | console.table(results) 58 | db.destroyClient() 59 | performance.mark("2-end") 60 | performance.measure("Test #2", "2-start", "2-end") 61 | } catch (/** @type {any} */ err) { 62 | console.error(`ERROR: ${err.toString()}`) 63 | } 64 | } 65 | 66 | 67 | /** 68 | * Test #2.1 Current Schema 69 | */ 70 | export async function test2_1() { 71 | performance.mark("2.1-start") 72 | try { 73 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 74 | let schema = await dbClass.schemaCalc({ schema: '**CURRENT_SCHEMA**' }, db) 75 | console.log(`Current Schema: ${schema}`) 76 | db.destroyClient() 77 | performance.mark("2.1-end") 78 | performance.measure("Test #2.1", "2.1-start", "2.1-end") 79 | } catch (/** @type {any} */ err) { 80 | console.error(`ERROR: ${err.toString()}`) 81 | } 82 | } 83 | 84 | 85 | /** 86 | * Test #2.2 87 | */ 88 | export async function test2_2() { 89 | performance.mark("2.2-start") 90 | try { 91 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 92 | const statement = await db.preparePromisified(`select top 50 SCHEMA_NAME, TABLE_NAME from TABLES WHERE SCHEMA_NAME = ?`) 93 | const results = await db.statementExecPromisified(statement, ['SYS']) 94 | console.table(results) 95 | db.destroyClient() 96 | performance.mark("2.2-end") 97 | performance.measure("Test #2.2", "2.2-start", "2.2-end") 98 | } catch (/** @type {any} */ err) { 99 | console.error(`ERROR: ${err.toString()}`) 100 | } 101 | } 102 | 103 | 104 | /** 105 | * Test #3 106 | */ 107 | export async function test3() { 108 | performance.mark("3-start") 109 | try { 110 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 111 | let sp = await db.loadProcedurePromisified('SYS', 'IS_VALID_PASSWORD') 112 | let output = await db.callProcedurePromisified(sp, { PASSWORD: "TEST" }) 113 | 114 | console.table(output) 115 | db.destroyClient() 116 | performance.mark("3-end") 117 | performance.measure("Test #3", "3-start", "3-end") 118 | } catch (/** @type {any} */ err) { 119 | console.error(`ERROR: ${err.toString()}`) 120 | } 121 | } 122 | 123 | export async function testUps() { 124 | try { 125 | xsenv.loadEnv() 126 | let userProvidedHanaEnv = xsenv.serviceCredentials({ label: 'user-provided' }) 127 | //console.log("credentials for user provided") 128 | //console.log(userProvidedHanaEnv) 129 | let connectionDetails = { hana: userProvidedHanaEnv } 130 | //console.log(connectionDetails.hana) 131 | // let db = new dbClass(await dbClass.createConnection(dbClass.resolveEnv(null))) 132 | const db = new dbClass(await dbClass.createConnection(connectionDetails)) 133 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 134 | FROM "DUMMY"`) 135 | const results = await db.statementExecPromisified(statement, []) 136 | console.table(results) 137 | db.destroyClient() 138 | } catch (/** @type {any} */ err) { 139 | console.error(`ERROR: ${err.toString()}`) 140 | } 141 | 142 | } 143 | 144 | test1() 145 | test2() 146 | test2_1() 147 | test2_2() 148 | test3() 149 | testUps() 150 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Promisfied Wrapper around @sap/hdbext and [hdb](hdb/README.md) 2 | 3 | [![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/hana-hdbext-promisfied-example)](https://api.reuse.software/info/github.com/SAP-samples/hana-hdbext-promisfied-example) 4 | 5 | ## Description 6 | 7 | With the standard @sap/hdbext you use nested events and callbacks like this: 8 | 9 | ```JavaScript 10 | let client = req.db; 11 | client.prepare( 12 | `SELECT SESSION_USER, CURRENT_SCHEMA 13 | FROM "DUMMY"`, 14 | (err, statement) => { 15 | if (err) { 16 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`); 17 | } 18 | statement.exec([], (err, results) => { 19 | if (err) { 20 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`); 21 | } else { 22 | var result = JSON.stringify({ 23 | Objects: results 24 | }); 25 | return res.type("application/json").status(200).send(result); 26 | } 27 | }); 28 | return null; 29 | }); 30 | ``` 31 | 32 | However this module wraps the major features of @sap/hdbext in a ES6 class and returns promises. Therefore you could re-write the above block using the easier to read and maintain promise based approach. You just pass in an instance of the HANA Client @sap/hdbext module. In this example its a typical example that gets the HANA client as Express Middelware (req.db): 33 | 34 | ```JavaScript 35 | const dbClass = require("sap-hdbext-promisfied") 36 | let db = new dbClass(req.db) 37 | db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 38 | FROM "DUMMY"`) 39 | .then(statement => { 40 | db.statementExecPromisified(statement, []) 41 | .then(results => { 42 | let result = JSON.stringify({ 43 | Objects: results 44 | }) 45 | return res.type("application/json").status(200).send(result) 46 | }) 47 | .catch(err => { 48 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`) 49 | }) 50 | }) 51 | .catch(err => { 52 | return res.type("text/plain").status(500).send(`ERROR: ${err.toString()}`) 53 | }) 54 | ``` 55 | 56 | Or better yet if you are running Node.js 8.x or higher you can use the new AWAIT feature and the code is even more streamlined: 57 | 58 | ```JavaScript 59 | try { 60 | const dbClass = require("sap-hdbext-promisfied") 61 | let db = new dbClass(req.db); 62 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 63 | FROM "DUMMY"`) 64 | const results = await db.statementExecPromisified(statement, []) 65 | let result = JSON.stringify({ 66 | Objects: results 67 | }) 68 | return res.type("application/json").status(200).send(result) 69 | } catch (e) { 70 | return res.type("text/plain").status(500).send(`ERROR: ${e.toString()}`) 71 | } 72 | ``` 73 | 74 | There are even static helpers to load the HANA connection information from the environment (or local testing file like default-env.json or .env) and create the HANA client for you. We can adjust the above example for such a scenario: 75 | 76 | ```JavaScript 77 | try { 78 | const dbClass = require("sap-hdbext-promisfied") 79 | let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null))) 80 | const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA 81 | FROM "DUMMY"`) 82 | const results = await db.statementExecPromisified(statement, []) 83 | console.table(results) 84 | } catch (e) { 85 | console.error(`ERROR: ${err.toString()}`) 86 | } 87 | ``` 88 | 89 | ### Methods 90 | 91 | The following @sap/hdbext functions are exposed as promise-based methods 92 | 93 | ```JavaScript 94 | prepare = preparePromisified(query) 95 | statement.exec = statementExecPromisified(statement, parameters) 96 | loadProcedure = loadProcedurePromisified(hdbext, schema, procedure) 97 | storedProc = callProcedurePromisified(storedProc, inputParams) 98 | ``` 99 | 100 | We also have the simplified helper method to both prepare and execute a simple statement via one command: 101 | 102 | ```JavaScript 103 | execSQL(sql) 104 | ``` 105 | 106 | And finally there are static helpers 107 | 108 | ```JavaScript 109 | createConnectionFromEnv(envFile) 110 | createConnection(options) 111 | resolveEnv(options) 112 | schemaCalc(options, db) 113 | objectName(name) 114 | ``` 115 | 116 | ## Requirements / Download and Installation 117 | 118 | * Install Node.js version 12.x or 14.x on your development machine [https://nodejs.org/en/download/](https://nodejs.org/en/download/) 119 | 120 | * @sap Node.js packages have moved from [https://npm.sap.com](https://npm.sap.com]) to the default registry . As future versions of @sap modules are going to be published only there, please make sure to adjust your registry with: 121 | 122 | ```shell 123 | npm config delete @sap:registry 124 | ``` 125 | 126 | * Install the code sample as a reusable Node.js module 127 | 128 | ```shell 129 | npm install -g sap-hdbext-promisfied 130 | ``` 131 | 132 | Or you can leverage this module by just listing as requirement in your own project's package.json. 133 | 134 | Finally you can clone the repository from [https://github.com/SAP-samples/hana-hdbext-promisified-example](https://github.com/SAP-samples/hana-hdbext-promisfied-example) to study the source content and view the consumption examples (test.js) 135 | 136 | ## Known Issues 137 | 138 | None 139 | 140 | ## How to obtain support 141 | 142 | This project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases. 143 | 144 | ## License 145 | 146 | Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSES/Apache-2.0.txt) file. 147 | -------------------------------------------------------------------------------- /hdbext/index.js: -------------------------------------------------------------------------------- 1 | /*eslint no-console: 0, no-unused-vars: 0, no-shadow: 0, new-cap: 0, dot-notation:0, no-use-before-define:0 */ 2 | /*eslint-env node, es6 */ 3 | // @ts-check 4 | 5 | import debugModule from 'debug' 6 | export const debug = new debugModule('hdbext-promisified') 7 | import * as dotenv from 'dotenv' 8 | import * as xsenv from '@sap/xsenv' 9 | import * as hdbext from '@sap/hdbext' 10 | import * as path from 'path' 11 | import { promisify } from 'util' 12 | 13 | /** 14 | * @module sap-hdbext-promisfied - promises version of sap/hdbext 15 | */ 16 | 17 | export default class dbClass { 18 | 19 | /** 20 | * Create Database Connection From Environment 21 | * @param {string} [envFile] - Override with a specific Environment File 22 | * @returns {Promise} - HANA Client instance of sap/hdbext 23 | */ 24 | static createConnectionFromEnv(envFile) { 25 | return new Promise((resolve, reject) => { 26 | dotenv.config() 27 | xsenv.loadEnv(envFile) 28 | 29 | /** @type any */ 30 | let options = '' 31 | try { 32 | if (!process.env.TARGET_CONTAINER) { 33 | options = xsenv.getServices({ hana: { tag: 'hana' } }) 34 | } else { 35 | options = xsenv.getServices({ hana: { name: process.env.TARGET_CONTAINER } }) 36 | } 37 | } catch (error) { 38 | try { 39 | options = xsenv.getServices({ hana: { tag: 'hana', plan: "hdi-shared" } }) 40 | } catch (error) { 41 | console.error(error) 42 | throw new Error(`Missing or badly formatted ${envFile}. No HANA configuration can be read or processed`) 43 | } 44 | } 45 | debug(`Connection Options`, options) 46 | options.hana.pooling = true 47 | hdbext.createConnection(options.hana, (error, client) => { 48 | if (error) { 49 | reject(error) 50 | } else { 51 | resolve(client) 52 | } 53 | }) 54 | }) 55 | } 56 | 57 | /** 58 | * Create Database Connection with specific connection options in format expected by sap/hdbext 59 | * @param {any} options - Input options or parameters 60 | * @returns {Promise} - HANA Client instance of sap/hdbext 61 | */ 62 | static createConnection(options) { 63 | return new Promise((resolve, reject) => { 64 | options.pooling = true 65 | debug(`Connection Options`, options) 66 | hdbext.createConnection(options, (error, client) => { 67 | if (error) { 68 | reject(error) 69 | } else { 70 | resolve(client) 71 | } 72 | }) 73 | }) 74 | } 75 | 76 | /** 77 | * Determine default env file name and location 78 | * @param {any} options - Input options or parameters 79 | * @returns string - default env file name and path 80 | */ 81 | static resolveEnv(options) { 82 | let file = 'default-env.json' 83 | if (options && options.hasOwnProperty('admin') && options.admin) { 84 | file = 'default-env-admin.json' 85 | } 86 | let envFile = path.resolve(process.cwd(), file) 87 | debug(`Environment File ${envFile}`) 88 | return envFile 89 | } 90 | 91 | /** 92 | * Calculation the current schema name 93 | * @param {any} options - Input options or parameters 94 | * @param {any} db - HANA Client instance of sap/hdbext 95 | * @returns {Promise} - Schema 96 | */ 97 | static async schemaCalc(options, db) { 98 | let schema = '' 99 | if (options.schema === '**CURRENT_SCHEMA**') { 100 | let schemaResults = await db.execSQL(`SELECT CURRENT_SCHEMA FROM DUMMY`) 101 | schema = schemaResults[0].CURRENT_SCHEMA 102 | } 103 | else if (options.schema === '*') { 104 | schema = "%" 105 | } 106 | else { 107 | schema = options.schema 108 | } 109 | debug(`Schema ${schema}`) 110 | return schema 111 | } 112 | 113 | /** 114 | * Calculation Object name from wildcards 115 | * @param {string} name - DB object name 116 | * @returns {string} - final object name 117 | */ 118 | static objectName(name) { 119 | if (typeof name === "undefined" || name === null || name === '*') { 120 | name = "%" 121 | } else { 122 | name += "%" 123 | } 124 | return name 125 | } 126 | 127 | /** 128 | * @constructor 129 | * @param {object} client - HANA DB Client instance of type sap/hdbext 130 | */ 131 | constructor(client) { 132 | this.client = client 133 | this.client.promisePrepare = promisify(this.client.prepare) 134 | } 135 | 136 | /** 137 | * Prepare database statement 138 | * @param {string} query - database query 139 | * @returns {any} - prepared statement object 140 | */ 141 | preparePromisified(query) { 142 | debug(`Query:`, query) 143 | return this.client.promisePrepare(query) 144 | } 145 | 146 | /** 147 | * Execute DB Statement in Batch 148 | * @param {any} statement - prepared statement object 149 | * @param {any} parameters - query parameters 150 | * @returns {Promise} - resultset 151 | */ 152 | statementExecBatchPromisified(statement, parameters) { 153 | statement.promiseExecBatch = promisify(statement.execBatch) 154 | return statement.promiseExecBatch(parameters) 155 | } 156 | 157 | /** 158 | * Execute DB Statement 159 | * @param {any} statement - prepared statement object 160 | * @param {any} parameters - query parameters 161 | * @returns {Promise} - resultset 162 | */ 163 | statementExecPromisified(statement, parameters) { 164 | statement.promiseExec = promisify(statement.exec) 165 | return statement.promiseExec(parameters) 166 | } 167 | 168 | /** 169 | * Load stored procedure and return proxy function 170 | * @param {any} hdbext - instance of db client sap/hdbext 171 | * @param {string} schema - Schema name can be null 172 | * @param {string} procedure - DB procedure name 173 | * @returns {Promise} - proxy function 174 | */ 175 | loadProcedurePromisified(hdbext, schema, procedure) { 176 | let promiseLoadProcedure = promisify(hdbext.loadProcedure) 177 | return promiseLoadProcedure(this.client, schema, procedure) 178 | } 179 | 180 | /** 181 | * Execute single SQL Statement and directly return result set 182 | * @param {string} sql - SQL Statement 183 | * @returns {Promise} - result set object 184 | */ 185 | execSQL(sql) { 186 | return new Promise((resolve, reject) => { 187 | this.preparePromisified(sql) 188 | .then(statement => { 189 | this.statementExecPromisified(statement, []) 190 | .then(results => { 191 | resolve(results) 192 | }) 193 | .catch(err => { 194 | reject(err) 195 | }); 196 | }) 197 | .catch(err => { 198 | reject(err) 199 | }) 200 | }) 201 | } 202 | 203 | /** 204 | * Call Database Procedure 205 | * @param {function} storedProc - stored procedure proxy function 206 | * @param {any} inputParams - input parameters for the stored procedure 207 | * @returns 208 | */ 209 | callProcedurePromisified(storedProc, inputParams) { 210 | return new Promise((resolve, reject) => { 211 | storedProc(inputParams, (error, outputScalar, ...results) => { 212 | if (error) { 213 | reject(error) 214 | } else { 215 | if (results.length < 2) { 216 | resolve({ 217 | outputScalar: outputScalar, 218 | results: results[0] 219 | }) 220 | } else { 221 | let output = {}; 222 | output.outputScalar = outputScalar; 223 | for (let i = 0; i < results.length; i++) { 224 | output[`results${i}`] = results[i] 225 | } 226 | resolve(output) 227 | } 228 | } 229 | }) 230 | }) 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /hdbext/index.cjs: -------------------------------------------------------------------------------- 1 | /*eslint no-console: 0, no-unused-vars: 0, no-shadow: 0, new-cap: 0, dot-notation:0, no-use-before-define:0 */ 2 | /*eslint-env node, es6 */ 3 | // @ts-check 4 | "use strict"; 5 | const debug = require('debug')('hdbext-promisified') 6 | 7 | /** 8 | * @module sap-hdbext-promisfied - promises version of sap/hdbext 9 | */ 10 | 11 | module.exports = class { 12 | 13 | /** 14 | * Create Database Connection From Environment 15 | * @param {string} [envFile] - Override with a specific Environment File 16 | * @returns {Promise} - HANA Client instance of sap/hdbext 17 | */ 18 | static createConnectionFromEnv(envFile) { 19 | return new Promise((resolve, reject) => { 20 | require('dotenv').config() 21 | const xsenv = require("@sap/xsenv") 22 | xsenv.loadEnv(envFile) 23 | 24 | /** @type any */ 25 | let options = '' 26 | try { 27 | if (!process.env.TARGET_CONTAINER) { 28 | options = xsenv.getServices({ hana: { tag: 'hana' } }) 29 | } else { 30 | options = xsenv.getServices({ hana: { name: process.env.TARGET_CONTAINER } }) 31 | } 32 | } catch (error) { 33 | try { 34 | options = xsenv.getServices({ hana: { tag: 'hana', plan: "hdi-shared" } }) 35 | } catch (error) { 36 | console.error(error) 37 | throw new Error(`Missing or badly formatted ${envFile}. No HANA configuration can be read or processed`) 38 | } 39 | } 40 | debug(`Connection Options`, options) 41 | var hdbext = require("@sap/hdbext") 42 | options.hana.pooling = true 43 | hdbext.createConnection(options.hana, (error, client) => { 44 | if (error) { 45 | reject(error) 46 | } else { 47 | resolve(client) 48 | } 49 | }) 50 | }) 51 | } 52 | 53 | /** 54 | * Create Database Connection with specific connection options in format expected by sap/hdbext 55 | * @param {any} options - Input options or parameters 56 | * @returns {Promise} - HANA Client instance of sap/hdbext 57 | */ 58 | static createConnection(options) { 59 | return new Promise((resolve, reject) => { 60 | var hdbext = require("@sap/hdbext") 61 | 62 | options.pooling = true 63 | debug(`Connection Options`, options) 64 | hdbext.createConnection(options, (error, client) => { 65 | if (error) { 66 | reject(error) 67 | } else { 68 | resolve(client) 69 | } 70 | }) 71 | }) 72 | } 73 | 74 | /** 75 | * Determine default env file name and location 76 | * @param {any} options - Input options or parameters 77 | * @returns string - default env file name and path 78 | */ 79 | static resolveEnv(options) { 80 | let path = require("path") 81 | let file = 'default-env.json' 82 | if (options && options.hasOwnProperty('admin') && options.admin) { 83 | file = 'default-env-admin.json' 84 | } 85 | let envFile = path.resolve(process.cwd(), file) 86 | debug(`Environment File ${envFile}`) 87 | return envFile 88 | } 89 | 90 | /** 91 | * Calculation the current schema name 92 | * @param {any} options - Input options or parameters 93 | * @param {any} db - HANA Client instance of sap/hdbext 94 | * @returns {Promise} - Schema 95 | */ 96 | static async schemaCalc(options, db) { 97 | let schema = '' 98 | if (options.schema === '**CURRENT_SCHEMA**') { 99 | let schemaResults = await db.execSQL(`SELECT CURRENT_SCHEMA FROM DUMMY`) 100 | schema = schemaResults[0].CURRENT_SCHEMA 101 | } 102 | else if (options.schema === '*') { 103 | schema = "%" 104 | } 105 | else { 106 | schema = options.schema 107 | } 108 | debug(`Schema ${schema}`) 109 | return schema 110 | } 111 | 112 | /** 113 | * Calculation Object name from wildcards 114 | * @param {string} name - DB object name 115 | * @returns {string} - final object name 116 | */ 117 | static objectName(name) { 118 | if (typeof name === "undefined" || name === null || name === '*') { 119 | name = "%" 120 | } else { 121 | name += "%" 122 | } 123 | return name 124 | } 125 | 126 | /** 127 | * @constructor 128 | * @param {object} client - HANA DB Client instance of type sap/hdbext 129 | */ 130 | constructor(client) { 131 | this.client = client 132 | this.util = require("util") 133 | this.client.promisePrepare = this.util.promisify(this.client.prepare) 134 | } 135 | 136 | /** 137 | * Prepare database statement 138 | * @param {string} query - database query 139 | * @returns {any} - prepared statement object 140 | */ 141 | preparePromisified(query) { 142 | debug(`Query:`, query) 143 | return this.client.promisePrepare(query) 144 | } 145 | 146 | /** 147 | * Execute DB Statement in Batch 148 | * @param {any} statement - prepared statement object 149 | * @param {any} parameters - query parameters 150 | * @returns {Promise} - resultset 151 | */ 152 | statementExecBatchPromisified(statement, parameters) { 153 | statement.promiseExecBatch = this.util.promisify(statement.execBatch) 154 | return statement.promiseExecBatch(parameters) 155 | } 156 | 157 | /** 158 | * Execute DB Statement 159 | * @param {any} statement - prepared statement object 160 | * @param {any} parameters - query parameters 161 | * @returns {Promise} - resultset 162 | */ 163 | statementExecPromisified(statement, parameters) { 164 | statement.promiseExec = this.util.promisify(statement.exec) 165 | return statement.promiseExec(parameters) 166 | } 167 | 168 | /** 169 | * Load stored procedure and return proxy function 170 | * @param {any} hdbext - instance of db client sap/hdbext 171 | * @param {string} schema - Schema name can be null 172 | * @param {string} procedure - DB procedure name 173 | * @returns {Promise} - proxy function 174 | */ 175 | loadProcedurePromisified(hdbext, schema, procedure) { 176 | hdbext.promiseLoadProcedure = this.util.promisify(hdbext.loadProcedure) 177 | return hdbext.promiseLoadProcedure(this.client, schema, procedure) 178 | } 179 | 180 | /** 181 | * Execute single SQL Statement and directly return result set 182 | * @param {string} sql - SQL Statement 183 | * @returns {Promise} - result set object 184 | */ 185 | execSQL(sql) { 186 | return new Promise((resolve, reject) => { 187 | this.preparePromisified(sql) 188 | .then(statement => { 189 | this.statementExecPromisified(statement, []) 190 | .then(results => { 191 | resolve(results) 192 | }) 193 | .catch(err => { 194 | reject(err) 195 | }); 196 | }) 197 | .catch(err => { 198 | reject(err) 199 | }) 200 | }) 201 | } 202 | 203 | /** 204 | * Call Database Procedure 205 | * @param {function} storedProc - stored procedure proxy function 206 | * @param {any} inputParams - input parameters for the stored procedure 207 | * @returns 208 | */ 209 | callProcedurePromisified(storedProc, inputParams) { 210 | return new Promise((resolve, reject) => { 211 | storedProc(inputParams, (error, outputScalar, ...results) => { 212 | if (error) { 213 | reject(error) 214 | } else { 215 | if (results.length < 2) { 216 | resolve({ 217 | outputScalar: outputScalar, 218 | results: results[0] 219 | }) 220 | } else { 221 | let output = {}; 222 | output.outputScalar = outputScalar; 223 | for (let i = 0; i < results.length; i++) { 224 | output[`results${i}`] = results[i] 225 | } 226 | resolve(output) 227 | } 228 | } 229 | }) 230 | }) 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /hdb/npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sap-hdb-promisfied", 3 | "version": "2.202510.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "sap-hdb-promisfied", 9 | "version": "2.202510.0", 10 | "license": "Apache-2.0", 11 | "dependencies": { 12 | "@sap/xsenv": "^6.0.0", 13 | "debug": "4.4.3", 14 | "dotenv": "^17.2.3", 15 | "hdb": "2.26.1" 16 | }, 17 | "devDependencies": { 18 | "@types/debug": "^4.1.12", 19 | "@types/node": "^24.9.2", 20 | "@types/sap__xsenv": "^3.3.2" 21 | }, 22 | "engines": { 23 | "node": ">= 18.18.0" 24 | } 25 | }, 26 | "node_modules/@sap/xsenv": { 27 | "version": "6.0.0", 28 | "resolved": "https://registry.npmjs.org/@sap/xsenv/-/xsenv-6.0.0.tgz", 29 | "integrity": "sha512-9bNpJXmxndWn5JbRCPPtbeMqldXOn2Od17ybS92PHd1rNkZ80IMmOURHNct5YSVQ1MKBIDAyC+ck6VL7cVAfUA==", 30 | "license": "SEE LICENSE IN LICENSE file", 31 | "dependencies": { 32 | "debug": "4.4.1", 33 | "node-cache": "^5.1.2", 34 | "verror": "1.10.1" 35 | }, 36 | "engines": { 37 | "node": "^20.0.0 || ^22.0.0 || ^24.0.0" 38 | } 39 | }, 40 | "node_modules/@sap/xsenv/node_modules/debug": { 41 | "version": "4.4.1", 42 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", 43 | "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", 44 | "license": "MIT", 45 | "dependencies": { 46 | "ms": "^2.1.3" 47 | }, 48 | "engines": { 49 | "node": ">=6.0" 50 | }, 51 | "peerDependenciesMeta": { 52 | "supports-color": { 53 | "optional": true 54 | } 55 | } 56 | }, 57 | "node_modules/@types/debug": { 58 | "version": "4.1.12", 59 | "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", 60 | "integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==", 61 | "dev": true, 62 | "license": "MIT", 63 | "dependencies": { 64 | "@types/ms": "*" 65 | } 66 | }, 67 | "node_modules/@types/ms": { 68 | "version": "2.1.0", 69 | "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", 70 | "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", 71 | "dev": true, 72 | "license": "MIT" 73 | }, 74 | "node_modules/@types/node": { 75 | "version": "24.9.2", 76 | "resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.2.tgz", 77 | "integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==", 78 | "dev": true, 79 | "license": "MIT", 80 | "dependencies": { 81 | "undici-types": "~7.16.0" 82 | } 83 | }, 84 | "node_modules/@types/sap__xsenv": { 85 | "version": "3.3.2", 86 | "resolved": "https://registry.npmjs.org/@types/sap__xsenv/-/sap__xsenv-3.3.2.tgz", 87 | "integrity": "sha512-yK6uL5yvXcMFkGjg+lWA3etJM6rQUFV3rstd118V3q0udMe5wcg+qB0poVTjKLZs4aX+n1DVrqukdRgVdwiK7g==", 88 | "dev": true, 89 | "license": "MIT" 90 | }, 91 | "node_modules/assert-plus": { 92 | "version": "1.0.0", 93 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", 94 | "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==", 95 | "license": "MIT", 96 | "engines": { 97 | "node": ">=0.8" 98 | } 99 | }, 100 | "node_modules/clone": { 101 | "version": "2.1.2", 102 | "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", 103 | "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", 104 | "license": "MIT", 105 | "engines": { 106 | "node": ">=0.8" 107 | } 108 | }, 109 | "node_modules/core-util-is": { 110 | "version": "1.0.2", 111 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 112 | "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", 113 | "license": "MIT" 114 | }, 115 | "node_modules/debug": { 116 | "version": "4.4.3", 117 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", 118 | "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", 119 | "license": "MIT", 120 | "dependencies": { 121 | "ms": "^2.1.3" 122 | }, 123 | "engines": { 124 | "node": ">=6.0" 125 | }, 126 | "peerDependenciesMeta": { 127 | "supports-color": { 128 | "optional": true 129 | } 130 | } 131 | }, 132 | "node_modules/dotenv": { 133 | "version": "17.2.3", 134 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", 135 | "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", 136 | "license": "BSD-2-Clause", 137 | "engines": { 138 | "node": ">=12" 139 | }, 140 | "funding": { 141 | "url": "https://dotenvx.com" 142 | } 143 | }, 144 | "node_modules/extsprintf": { 145 | "version": "1.4.1", 146 | "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.1.tgz", 147 | "integrity": "sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==", 148 | "engines": [ 149 | "node >=0.6.0" 150 | ], 151 | "license": "MIT" 152 | }, 153 | "node_modules/hdb": { 154 | "version": "2.26.1", 155 | "resolved": "https://registry.npmjs.org/hdb/-/hdb-2.26.1.tgz", 156 | "integrity": "sha512-m8X1ugfxgbrUIB6o9Mpvm7IrgMBfChBoG1m6JxuJWjdg5g36eXInE4wbCYMRH8UPO2g0Y/Fswu42t3XA6tntLg==", 157 | "license": "Apache-2.0", 158 | "dependencies": { 159 | "iconv-lite": "^0.4.18" 160 | }, 161 | "engines": { 162 | "node": ">= 18" 163 | }, 164 | "optionalDependencies": { 165 | "lz4-wasm-nodejs": "^0.9.2" 166 | } 167 | }, 168 | "node_modules/iconv-lite": { 169 | "version": "0.4.24", 170 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 171 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 172 | "license": "MIT", 173 | "dependencies": { 174 | "safer-buffer": ">= 2.1.2 < 3" 175 | }, 176 | "engines": { 177 | "node": ">=0.10.0" 178 | } 179 | }, 180 | "node_modules/lz4-wasm-nodejs": { 181 | "version": "0.9.2", 182 | "resolved": "https://registry.npmjs.org/lz4-wasm-nodejs/-/lz4-wasm-nodejs-0.9.2.tgz", 183 | "integrity": "sha512-hSwgJPS98q/Oe/89Y1OxzeA/UdnASG8GvldRyKa7aZyoAFCC8VPRtViBSava7wWC66WocjUwBpWau2rEmyFPsw==", 184 | "license": "MIT", 185 | "optional": true 186 | }, 187 | "node_modules/ms": { 188 | "version": "2.1.3", 189 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", 190 | "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", 191 | "license": "MIT" 192 | }, 193 | "node_modules/node-cache": { 194 | "version": "5.1.2", 195 | "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", 196 | "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==", 197 | "license": "MIT", 198 | "dependencies": { 199 | "clone": "2.x" 200 | }, 201 | "engines": { 202 | "node": ">= 8.0.0" 203 | } 204 | }, 205 | "node_modules/safer-buffer": { 206 | "version": "2.1.2", 207 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 208 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", 209 | "license": "MIT" 210 | }, 211 | "node_modules/undici-types": { 212 | "version": "7.16.0", 213 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", 214 | "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", 215 | "dev": true, 216 | "license": "MIT" 217 | }, 218 | "node_modules/verror": { 219 | "version": "1.10.1", 220 | "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz", 221 | "integrity": "sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==", 222 | "license": "MIT", 223 | "dependencies": { 224 | "assert-plus": "^1.0.0", 225 | "core-util-is": "1.0.2", 226 | "extsprintf": "^1.2.0" 227 | }, 228 | "engines": { 229 | "node": ">=0.6.0" 230 | } 231 | } 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2024] [SAP SE] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSES/Apache-2.0.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2024] [SAP SE] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /hdbext/npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sap-hdbext-promisfied", 3 | "version": "2.202510.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "sap-hdbext-promisfied", 9 | "version": "2.202510.0", 10 | "license": "Apache-2.0", 11 | "dependencies": { 12 | "@sap/hdbext": "^8.1.9", 13 | "@sap/xsenv": "^6.0.0", 14 | "debug": "^4.4.3", 15 | "dotenv": "^17.2.3" 16 | }, 17 | "devDependencies": { 18 | "@types/node": "^24.9.2" 19 | }, 20 | "engines": { 21 | "node": ">=18.18.0" 22 | } 23 | }, 24 | "node_modules/@sap/hdbext": { 25 | "version": "8.1.9", 26 | "resolved": "https://registry.npmjs.org/@sap/hdbext/-/hdbext-8.1.9.tgz", 27 | "integrity": "sha512-se9t7INPr4oZ/FkzxCbvI+LlaBBHa4uBT24eYKZ/V5r/H5ceaqNC89xNcfKoL1wzPuU42H/wJZcgjBrs+ph4xw==", 28 | "hasShrinkwrap": true, 29 | "license": "SEE LICENSE IN LICENSE file", 30 | "dependencies": { 31 | "@sap/e2e-trace": "5.3.0", 32 | "@sap/hana-client": "2.24.26", 33 | "accept-language": "2.0.16", 34 | "async": "3.2.6", 35 | "debug": "4.3.1", 36 | "lodash": "4.17.21", 37 | "verror": "1.10.0" 38 | }, 39 | "engines": { 40 | "node": "^16.0.0 || ^18.0.0 || ^20.0.0 || ^22.x" 41 | } 42 | }, 43 | "node_modules/@sap/hdbext/node_modules/@sap/e2e-trace": { 44 | "version": "5.3.0", 45 | "license": "SEE LICENSE IN LICENSE file", 46 | "dependencies": { 47 | "request-stats": "3.0.0" 48 | }, 49 | "engines": { 50 | "node": "^18.0.0 || ^20.0.0 || ^22.0.0" 51 | } 52 | }, 53 | "node_modules/@sap/hdbext/node_modules/@sap/hana-client": { 54 | "version": "2.24.26", 55 | "hasInstallScript": true, 56 | "license": "SEE LICENSE IN developer-license-3_2.txt", 57 | "dependencies": { 58 | "debug": "3.1.0" 59 | }, 60 | "engines": { 61 | "node": ">=4.0.0" 62 | } 63 | }, 64 | "node_modules/@sap/hdbext/node_modules/@sap/hana-client/node_modules/debug": { 65 | "version": "3.1.0", 66 | "license": "MIT", 67 | "dependencies": { 68 | "ms": "2.0.0" 69 | } 70 | }, 71 | "node_modules/@sap/hdbext/node_modules/@sap/hana-client/node_modules/ms": { 72 | "version": "2.0.0", 73 | "license": "MIT" 74 | }, 75 | "node_modules/@sap/hdbext/node_modules/accept-language": { 76 | "version": "2.0.16", 77 | "license": "MIT", 78 | "dependencies": { 79 | "bcp47": "^1.1.2" 80 | } 81 | }, 82 | "node_modules/@sap/hdbext/node_modules/assert-plus": { 83 | "version": "1.0.0", 84 | "license": "MIT", 85 | "engines": { 86 | "node": ">=0.8" 87 | } 88 | }, 89 | "node_modules/@sap/hdbext/node_modules/async": { 90 | "version": "3.2.6", 91 | "license": "MIT" 92 | }, 93 | "node_modules/@sap/hdbext/node_modules/bcp47": { 94 | "version": "1.1.2", 95 | "license": "MIT", 96 | "engines": { 97 | "node": ">=0.10" 98 | } 99 | }, 100 | "node_modules/@sap/hdbext/node_modules/core-util-is": { 101 | "version": "1.0.2", 102 | "license": "MIT" 103 | }, 104 | "node_modules/@sap/hdbext/node_modules/debug": { 105 | "version": "4.3.1", 106 | "license": "MIT", 107 | "dependencies": { 108 | "ms": "2.1.2" 109 | }, 110 | "engines": { 111 | "node": ">=6.0" 112 | }, 113 | "peerDependenciesMeta": { 114 | "supports-color": { 115 | "optional": true 116 | } 117 | } 118 | }, 119 | "node_modules/@sap/hdbext/node_modules/extsprintf": { 120 | "version": "1.4.1", 121 | "engines": [ 122 | "node >=0.6.0" 123 | ], 124 | "license": "MIT" 125 | }, 126 | "node_modules/@sap/hdbext/node_modules/http-headers": { 127 | "version": "3.0.2", 128 | "license": "MIT", 129 | "dependencies": { 130 | "next-line": "^1.1.0" 131 | } 132 | }, 133 | "node_modules/@sap/hdbext/node_modules/lodash": { 134 | "version": "4.17.21", 135 | "license": "MIT" 136 | }, 137 | "node_modules/@sap/hdbext/node_modules/ms": { 138 | "version": "2.1.2", 139 | "license": "MIT" 140 | }, 141 | "node_modules/@sap/hdbext/node_modules/next-line": { 142 | "version": "1.1.0", 143 | "license": "MIT" 144 | }, 145 | "node_modules/@sap/hdbext/node_modules/once": { 146 | "version": "1.4.0", 147 | "license": "ISC", 148 | "dependencies": { 149 | "wrappy": "1" 150 | } 151 | }, 152 | "node_modules/@sap/hdbext/node_modules/request-stats": { 153 | "version": "3.0.0", 154 | "license": "MIT", 155 | "dependencies": { 156 | "http-headers": "^3.0.1", 157 | "once": "^1.4.0" 158 | }, 159 | "engines": { 160 | "node": ">=0.12" 161 | } 162 | }, 163 | "node_modules/@sap/hdbext/node_modules/verror": { 164 | "version": "1.10.0", 165 | "engines": [ 166 | "node >=0.6.0" 167 | ], 168 | "license": "MIT", 169 | "dependencies": { 170 | "assert-plus": "^1.0.0", 171 | "core-util-is": "1.0.2", 172 | "extsprintf": "^1.2.0" 173 | } 174 | }, 175 | "node_modules/@sap/hdbext/node_modules/wrappy": { 176 | "version": "1.0.2", 177 | "license": "ISC" 178 | }, 179 | "node_modules/@sap/xsenv": { 180 | "version": "6.0.0", 181 | "resolved": "https://registry.npmjs.org/@sap/xsenv/-/xsenv-6.0.0.tgz", 182 | "integrity": "sha512-9bNpJXmxndWn5JbRCPPtbeMqldXOn2Od17ybS92PHd1rNkZ80IMmOURHNct5YSVQ1MKBIDAyC+ck6VL7cVAfUA==", 183 | "license": "SEE LICENSE IN LICENSE file", 184 | "dependencies": { 185 | "debug": "4.4.1", 186 | "node-cache": "^5.1.2", 187 | "verror": "1.10.1" 188 | }, 189 | "engines": { 190 | "node": "^20.0.0 || ^22.0.0 || ^24.0.0" 191 | } 192 | }, 193 | "node_modules/@sap/xsenv/node_modules/debug": { 194 | "version": "4.4.1", 195 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", 196 | "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", 197 | "license": "MIT", 198 | "dependencies": { 199 | "ms": "^2.1.3" 200 | }, 201 | "engines": { 202 | "node": ">=6.0" 203 | }, 204 | "peerDependenciesMeta": { 205 | "supports-color": { 206 | "optional": true 207 | } 208 | } 209 | }, 210 | "node_modules/@types/node": { 211 | "version": "24.9.2", 212 | "resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.2.tgz", 213 | "integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==", 214 | "dev": true, 215 | "license": "MIT", 216 | "dependencies": { 217 | "undici-types": "~7.16.0" 218 | } 219 | }, 220 | "node_modules/assert-plus": { 221 | "version": "1.0.0", 222 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", 223 | "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==", 224 | "license": "MIT", 225 | "engines": { 226 | "node": ">=0.8" 227 | } 228 | }, 229 | "node_modules/clone": { 230 | "version": "2.1.2", 231 | "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", 232 | "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", 233 | "license": "MIT", 234 | "engines": { 235 | "node": ">=0.8" 236 | } 237 | }, 238 | "node_modules/core-util-is": { 239 | "version": "1.0.2", 240 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 241 | "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", 242 | "license": "MIT" 243 | }, 244 | "node_modules/debug": { 245 | "version": "4.4.3", 246 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", 247 | "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", 248 | "license": "MIT", 249 | "dependencies": { 250 | "ms": "^2.1.3" 251 | }, 252 | "engines": { 253 | "node": ">=6.0" 254 | }, 255 | "peerDependenciesMeta": { 256 | "supports-color": { 257 | "optional": true 258 | } 259 | } 260 | }, 261 | "node_modules/dotenv": { 262 | "version": "17.2.3", 263 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", 264 | "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", 265 | "license": "BSD-2-Clause", 266 | "engines": { 267 | "node": ">=12" 268 | }, 269 | "funding": { 270 | "url": "https://dotenvx.com" 271 | } 272 | }, 273 | "node_modules/extsprintf": { 274 | "version": "1.4.1", 275 | "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.1.tgz", 276 | "integrity": "sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==", 277 | "engines": [ 278 | "node >=0.6.0" 279 | ], 280 | "license": "MIT" 281 | }, 282 | "node_modules/ms": { 283 | "version": "2.1.3", 284 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", 285 | "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", 286 | "license": "MIT" 287 | }, 288 | "node_modules/node-cache": { 289 | "version": "5.1.2", 290 | "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", 291 | "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==", 292 | "license": "MIT", 293 | "dependencies": { 294 | "clone": "2.x" 295 | }, 296 | "engines": { 297 | "node": ">= 8.0.0" 298 | } 299 | }, 300 | "node_modules/undici-types": { 301 | "version": "7.16.0", 302 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", 303 | "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", 304 | "dev": true, 305 | "license": "MIT" 306 | }, 307 | "node_modules/verror": { 308 | "version": "1.10.1", 309 | "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz", 310 | "integrity": "sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==", 311 | "license": "MIT", 312 | "dependencies": { 313 | "assert-plus": "^1.0.0", 314 | "core-util-is": "1.0.2", 315 | "extsprintf": "^1.2.0" 316 | }, 317 | "engines": { 318 | "node": ">=0.6.0" 319 | } 320 | } 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /hdb/index.js: -------------------------------------------------------------------------------- 1 | /*eslint no-console: 0, no-unused-vars: 0, no-shadow: 0, new-cap: 0, dot-notation:0, no-use-before-define:0 */ 2 | /*eslint-env node, es6 */ 3 | // @ts-check 4 | 5 | import debugModule from 'debug' 6 | // @ts-ignore 7 | export const debug = new debugModule('hdb-promisified') 8 | import * as dotenv from 'dotenv' 9 | import * as xsenv from '@sap/xsenv' 10 | // @ts-ignore 11 | import * as hdb from 'hdb' 12 | import * as path from 'path' 13 | import { promisify } from 'util' 14 | 15 | /** 16 | * @module sap-hdb-promisfied - promises version of hdb 17 | */ 18 | 19 | export default class dbClass { 20 | 21 | /** 22 | * Create Database Connection From Environment 23 | * @param {string} [envFile] - Override with a specific Environment File 24 | * @returns {Promise} - HANA Client instance of hdb 25 | */ 26 | static createConnectionFromEnv(envFile) { 27 | return new Promise((resolve, reject) => { 28 | dotenv.config() 29 | xsenv.loadEnv(envFile) 30 | 31 | /** @type any */ 32 | let options = '' 33 | try { 34 | if (!process.env.TARGET_CONTAINER) { 35 | options = xsenv.getServices({ hana: { tag: 'hana' } }) 36 | } else { 37 | options = xsenv.getServices({ hana: { name: process.env.TARGET_CONTAINER } }) 38 | } 39 | } catch (error) { 40 | try { 41 | options = xsenv.getServices({ hana: { tag: 'hana', plan: "hdi-shared" } }) 42 | } catch (error) { 43 | console.error(error) 44 | throw new Error(`Missing or badly formatted ${envFile}. No HANA configuration can be read or processed`) 45 | } 46 | } 47 | if(options && options.hana && options.hana.encrypt){ 48 | options.hana.useTLS = true 49 | } 50 | 51 | debug(`Connection Options`, options) 52 | let client = hdb.createClient(options.hana) 53 | client.on('error', (/** @type {any} */ err) => { 54 | console.log(`In Client On Error`) 55 | reject(err) 56 | }) 57 | debug(`Client Ready State`, client.readyState) 58 | 59 | client.connect(async (/** @type {any} */ err) => { 60 | if (err) { 61 | reject(err) 62 | } 63 | await dbClass.setSchema(options, client) 64 | resolve(client) 65 | }) 66 | }) 67 | } 68 | 69 | /** 70 | * Create Database Connection with specific connection options in format expected by hdb 71 | * @param {any} options - Input options or parameters 72 | * @returns {Promise} - HANA Client instance of hdb 73 | */ 74 | static createConnection(options) { 75 | return new Promise(async function (resolve, reject) { 76 | if(options && options.hana && options.hana.encrypt){ 77 | options.hana.useTLS = true 78 | } 79 | debug(`Connection Options`, options) 80 | let client = hdb.createClient(options.hana) 81 | client.on('error', (/** @type {any} */ err) => { 82 | reject(err) 83 | }) 84 | client.connect(async (/** @type {any} */ err) => { 85 | if (err) { 86 | reject(err) 87 | } 88 | await dbClass.setSchema(options, client) 89 | resolve(client) 90 | }) 91 | }) 92 | } 93 | 94 | /** 95 | * Set default schema based upon connection parameters 96 | * @param {any} options - Input options or parameters 97 | * @param {any} client - HANA Client instance of hdb 98 | */ 99 | static async setSchema(options, client) { 100 | if (options.hana) { 101 | if (options.hana.schema) { 102 | client.exec(`SET SCHEMA ${options.hana.schema}`, function () { 103 | return 104 | }) 105 | } 106 | } 107 | } 108 | 109 | /** 110 | * Determine default env file name and location 111 | * @param {any} options - Input options or parameters 112 | * @returns string - default env file name and path 113 | */ 114 | static resolveEnv(options) { 115 | let file = 'default-env.json' 116 | if (options && options.hasOwnProperty('admin') && options.admin) { 117 | file = 'default-env-admin.json' 118 | } 119 | let envFile = path.resolve(process.cwd(), file) 120 | debug(`Environment File ${envFile}`) 121 | return envFile 122 | } 123 | 124 | /** 125 | * Calculation the current schema name 126 | * @param {any} options - Input options or parameters 127 | * @param {any} db - HANA Client instance of hdb 128 | * @returns {Promise} - Schema 129 | */ 130 | static async schemaCalc(options, db) { 131 | let schema = '' 132 | if (options.schema === '**CURRENT_SCHEMA**') { 133 | let schemaResults = await db.execSQL(`SELECT CURRENT_SCHEMA FROM DUMMY`) 134 | schema = schemaResults[0].CURRENT_SCHEMA 135 | } 136 | else if (options.schema === '*') { 137 | schema = "%" 138 | } 139 | else { 140 | schema = options.schema 141 | } 142 | debug(`Schema ${schema}`) 143 | return schema 144 | } 145 | 146 | /** 147 | * Load Metadata of a Stored Procedure 148 | * @param {any} db - HANA Client instance of hdb 149 | * @param {any} procInfo - Details of Schema/Stored Procedure to Lookup 150 | * @returns {Promise} - Result Set 151 | */ 152 | static async fetchSPMetadata(db, procInfo) { 153 | var sqlProcedureMetadata = "SELECT \ 154 | PARAMS.PARAMETER_NAME, \ 155 | PARAMS.DATA_TYPE_NAME, \ 156 | PARAMS.PARAMETER_TYPE, \ 157 | PARAMS.HAS_DEFAULT_VALUE, \ 158 | PARAMS.IS_INPLACE_TYPE, \ 159 | PARAMS.TABLE_TYPE_SCHEMA, \ 160 | PARAMS.TABLE_TYPE_NAME, \ 161 | \ 162 | CASE WHEN SYNONYMS.OBJECT_NAME IS NULL THEN 'FALSE' ELSE 'TRUE' END AS IS_TABLE_TYPE_SYNONYM, \ 163 | IFNULL(SYNONYMS.OBJECT_SCHEMA, '') AS OBJECT_SCHEMA, \ 164 | IFNULL(SYNONYMS.OBJECT_NAME, '') AS OBJECT_NAME \ 165 | \ 166 | FROM SYS.PROCEDURE_PARAMETERS AS PARAMS \ 167 | LEFT JOIN SYS.SYNONYMS AS SYNONYMS \ 168 | ON SYNONYMS.SCHEMA_NAME = PARAMS.TABLE_TYPE_SCHEMA AND SYNONYMS.SYNONYM_NAME = PARAMS.TABLE_TYPE_NAME \ 169 | WHERE PARAMS.SCHEMA_NAME = ? AND PARAMS.PROCEDURE_NAME = ? \ 170 | ORDER BY PARAMS.POSITION" 171 | return await db.statementExecPromisified(await db.preparePromisified(sqlProcedureMetadata), [procInfo.schema, procInfo.name]) 172 | } 173 | 174 | /** 175 | * Calculation Object name from wildcards 176 | * @param {string} name - DB object name 177 | * @returns {string} - final object name 178 | */ 179 | static objectName(name) { 180 | if (typeof name === "undefined" || name === null || name === '*') { 181 | name = "%" 182 | } else { 183 | name += "%" 184 | } 185 | return name 186 | } 187 | 188 | /** 189 | * @constructor 190 | * @param {object} client - HANA DB Client instance of type hdb 191 | */ 192 | constructor(client) { 193 | this.client = client 194 | // @ts-ignore 195 | this.client.promisePrepare = promisify(this.client.prepare) 196 | } 197 | 198 | /** 199 | * Destroy Client 200 | */ 201 | destroyClient() { 202 | // @ts-ignore 203 | if (!this.client.hadError && this.client.readyState !== 'closed') { 204 | // @ts-ignore 205 | this.client.end() 206 | } 207 | } 208 | 209 | /** 210 | * Destroy Client 211 | */ 212 | validateClient() { 213 | // @ts-ignore 214 | return (!this.client.hadError && this.client.readyState === 'connected') 215 | } 216 | 217 | /** 218 | * Prepare database statement 219 | * @param {string} query - database query 220 | * @returns {any} - prepared statement object 221 | */ 222 | preparePromisified(query) { 223 | debug(`Query:`, query) 224 | // @ts-ignore 225 | return this.client.promisePrepare(query) 226 | } 227 | 228 | /** 229 | * Execute DB Statement in Batch 230 | * @param {any} statement - prepared statement object 231 | * @param {any} parameters - query parameters 232 | * @returns {Promise} - resultset 233 | */ 234 | statementExecBatchPromisified(statement, parameters) { 235 | statement.promiseExecBatch = promisify(statement.execBatch) 236 | return statement.promiseExecBatch(parameters) 237 | } 238 | 239 | /** 240 | * Execute DB Statement 241 | * @param {any} statement - prepared statement object 242 | * @param {any} parameters - query parameters 243 | * @returns {Promise} - resultset 244 | */ 245 | statementExecPromisified(statement, parameters) { 246 | statement.promiseExec = promisify(statement.exec) 247 | return statement.promiseExec(parameters) 248 | } 249 | 250 | /** 251 | * Load stored procedure and return proxy function 252 | * @param {string} schema - Schema name can be null 253 | * @param {string} procedure - DB procedure name 254 | * @returns {Promise} - proxy function 255 | */ 256 | async loadProcedurePromisified(schema, procedure) { 257 | if (!schema) { 258 | schema = await dbClass.schemaCalc({ schema: '**CURRENT_SCHEMA**' }, this) 259 | } 260 | let procedureMetaData = await dbClass.fetchSPMetadata(this, { schema: schema, name: procedure }) 261 | let callString = '' 262 | procedureMetaData.forEach(() => { 263 | if (callString === '') { 264 | callString += `?` 265 | } else { 266 | callString += `,?` 267 | } 268 | }) 269 | 270 | return this.preparePromisified(`CALL ${schema}."${procedure}"(${callString})`) 271 | } 272 | 273 | 274 | /** 275 | * Execute single SQL Statement and directly return result set 276 | * @param {string} sql - SQL Statement 277 | * @returns {Promise} - result set object 278 | */ 279 | execSQL(sql) { 280 | return new Promise((resolve, reject) => { 281 | this.preparePromisified(sql) 282 | .then((/** @type {any} */ statement) => { 283 | this.statementExecPromisified(statement, []) 284 | .then(results => { 285 | resolve(results) 286 | }) 287 | .catch(err => { 288 | reject(err) 289 | }); 290 | }) 291 | .catch((/** @type {any} */ err) => { 292 | reject(err) 293 | }) 294 | }) 295 | } 296 | 297 | /** 298 | * Call Database Procedure 299 | * @param {any} storedProc - stored procedure proxy function 300 | * @param {any} inputParams - input parameters for the stored procedure 301 | * @returns 302 | */ 303 | callProcedurePromisified(storedProc, inputParams) { 304 | return new Promise((resolve, reject) => { 305 | // @ts-ignore 306 | storedProc.exec(inputParams, (/** @type {any} */ error, /** @type {any} */ outputScalar, /** @type {string | any[]} */ ...results) => { 307 | 308 | // storedProc(inputParams, (error, outputScalar, ...results) => { 309 | if (error) { 310 | reject(error) 311 | } else { 312 | if (results.length < 2) { 313 | resolve({ 314 | outputScalar: outputScalar, 315 | results: results[0] 316 | }) 317 | } else { 318 | let output = {}; 319 | output.outputScalar = outputScalar; 320 | for (let i = 0; i < results.length; i++) { 321 | // @ts-ignore 322 | output[`results${i}`] = results[i] 323 | } 324 | resolve(output) 325 | } 326 | } 327 | }) 328 | }) 329 | } 330 | 331 | } 332 | 333 | -------------------------------------------------------------------------------- /hdb/index.cjs: -------------------------------------------------------------------------------- 1 | /*eslint no-console: 0, no-unused-vars: 0, no-shadow: 0, new-cap: 0, dot-notation:0, no-use-before-define:0 */ 2 | /*eslint-env node, es6 */ 3 | // @ts-check 4 | "use strict" 5 | // @ts-ignore 6 | const debug = require('debug')('hdb-promisified') 7 | const dotenv = require('dotenv') 8 | const xsenv = require("@sap/xsenv") 9 | // @ts-ignore 10 | const hdb = require("hdb") 11 | const path = require("path") 12 | 13 | /** 14 | * @module sap-hdb-promisfied - promises version of hdb 15 | */ 16 | 17 | module.exports = class { 18 | 19 | /** 20 | * Create Database Connection From Environment 21 | * @param {string} [envFile] - Override with a specific Environment File 22 | * @returns {Promise} - HANA Client instance of hdb 23 | */ 24 | static createConnectionFromEnv(envFile) { 25 | const setSchema = this.setSchema 26 | return new Promise((resolve, reject) => { 27 | dotenv.config() 28 | xsenv.loadEnv(envFile) 29 | 30 | /** @type any */ 31 | let options = '' 32 | try { 33 | if (!process.env.TARGET_CONTAINER) { 34 | options = xsenv.getServices({ hana: { tag: 'hana' } }) 35 | } else { 36 | options = xsenv.getServices({ hana: { name: process.env.TARGET_CONTAINER } }) 37 | } 38 | } catch (error) { 39 | try { 40 | options = xsenv.getServices({ hana: { tag: 'hana', plan: "hdi-shared" } }) 41 | } catch (error) { 42 | console.error(error) 43 | throw new Error(`Missing or badly formatted ${envFile}. No HANA configuration can be read or processed`) 44 | } 45 | } 46 | //console.log(options) 47 | if(options && options.hana && options.hana.encrypt){ 48 | options.hana.useTLS = true 49 | } 50 | 51 | debug(`Connection Options`, options) 52 | let client = hdb.createClient(options.hana) 53 | client.on('error', (/** @type {any} */ err) => { 54 | console.log(`In Client On Error`) 55 | reject(err) 56 | }) 57 | debug(`Client Ready State`, client.readyState) 58 | 59 | client.connect(async (/** @type {any} */ err) => { 60 | if (err) { 61 | reject(err) 62 | } 63 | await setSchema(options, client) 64 | resolve(client) 65 | }) 66 | }) 67 | } 68 | 69 | /** 70 | * Create Database Connection with specific connection options in format expected by hdb 71 | * @param {any} options - Input options or parameters 72 | * @returns {Promise} - HANA Client instance of hdb 73 | */ 74 | static async createConnection(options) { 75 | const setSchema = this.setSchema 76 | return new Promise(async function (resolve, reject) { 77 | if(options && options.hana && options.hana.encrypt){ 78 | options.hana.useTLS = true 79 | } 80 | debug(`Connection Options`, options) 81 | let client = hdb.createClient(options.hana) 82 | client.on('error', (/** @type {any} */ err) => { 83 | reject(err) 84 | }) 85 | client.connect(async (/** @type {any} */ err) => { 86 | if (err) { 87 | reject(err) 88 | } 89 | await setSchema(options, client) 90 | resolve(client) 91 | }) 92 | }) 93 | } 94 | 95 | /** 96 | * Set default schema based upon connection parameters 97 | * @param {any} options - Input options or parameters 98 | * @param {any} client - HANA Client instance of hdb 99 | */ 100 | static async setSchema(options, client){ 101 | if(options.hana){ 102 | if(options.hana.schema){ 103 | client.exec(`SET SCHEMA ${options.hana.schema}`, function () { 104 | return 105 | }) 106 | } 107 | } 108 | } 109 | 110 | /** 111 | * Determine default env file name and location 112 | * @param {any} options - Input options or parameters 113 | * @returns string - default env file name and path 114 | */ 115 | static resolveEnv(options) { 116 | let file = 'default-env.json' 117 | if (options && options.hasOwnProperty('admin') && options.admin) { 118 | file = 'default-env-admin.json' 119 | } 120 | let envFile = path.resolve(process.cwd(), file) 121 | debug(`Environment File ${envFile}`) 122 | return envFile 123 | } 124 | 125 | /** 126 | * Calculation the current schema name 127 | * @param {any} options - Input options or parameters 128 | * @param {any} db - HANA Client instance of hdb 129 | * @returns {Promise} - Schema 130 | */ 131 | async schemaCalc(options, db) { 132 | let schema = '' 133 | if (options.schema === '**CURRENT_SCHEMA**') { 134 | let schemaResults = await db.execSQL(`SELECT CURRENT_SCHEMA FROM DUMMY`) 135 | schema = schemaResults[0].CURRENT_SCHEMA 136 | } 137 | else if (options.schema === '*') { 138 | schema = "%" 139 | } 140 | else { 141 | schema = options.schema 142 | } 143 | debug(`Schema ${schema}`) 144 | return schema 145 | } 146 | 147 | /** 148 | * Load Metadata of a Stored Procedure 149 | * @param {any} db - HANA Client instance of hdb 150 | * @param {any} procInfo - Details of Schema/Stored Procedure to Lookup 151 | * @returns {Promise} - Result Set 152 | */ 153 | async fetchSPMetadata(db, procInfo) { 154 | var sqlProcedureMetadata = "SELECT \ 155 | PARAMS.PARAMETER_NAME, \ 156 | PARAMS.DATA_TYPE_NAME, \ 157 | PARAMS.PARAMETER_TYPE, \ 158 | PARAMS.HAS_DEFAULT_VALUE, \ 159 | PARAMS.IS_INPLACE_TYPE, \ 160 | PARAMS.TABLE_TYPE_SCHEMA, \ 161 | PARAMS.TABLE_TYPE_NAME, \ 162 | \ 163 | CASE WHEN SYNONYMS.OBJECT_NAME IS NULL THEN 'FALSE' ELSE 'TRUE' END AS IS_TABLE_TYPE_SYNONYM, \ 164 | IFNULL(SYNONYMS.OBJECT_SCHEMA, '') AS OBJECT_SCHEMA, \ 165 | IFNULL(SYNONYMS.OBJECT_NAME, '') AS OBJECT_NAME \ 166 | \ 167 | FROM SYS.PROCEDURE_PARAMETERS AS PARAMS \ 168 | LEFT JOIN SYS.SYNONYMS AS SYNONYMS \ 169 | ON SYNONYMS.SCHEMA_NAME = PARAMS.TABLE_TYPE_SCHEMA AND SYNONYMS.SYNONYM_NAME = PARAMS.TABLE_TYPE_NAME \ 170 | WHERE PARAMS.SCHEMA_NAME = ? AND PARAMS.PROCEDURE_NAME = ? \ 171 | ORDER BY PARAMS.POSITION" 172 | return await db.statementExecPromisified(await db.preparePromisified(sqlProcedureMetadata), [procInfo.schema, procInfo.name]) 173 | } 174 | 175 | /** 176 | * Calculation Object name from wildcards 177 | * @param {string} name - DB object name 178 | * @returns {string} - final object name 179 | */ 180 | static objectName(name) { 181 | if (typeof name === "undefined" || name === null || name === '*') { 182 | name = "%" 183 | } else { 184 | name += "%" 185 | } 186 | return name 187 | } 188 | 189 | /** 190 | * @constructor 191 | * @param {object} client - HANA DB Client instance of type hdb 192 | */ 193 | constructor(client) { 194 | this.client = client 195 | // @ts-ignore 196 | this.util = require("util") 197 | this.client.promisePrepare = this.util.promisify(this.client.prepare) 198 | } 199 | 200 | /** 201 | * Destroy Client 202 | */ 203 | destroyClient() { 204 | // @ts-ignore 205 | if (!this.client.hadError && this.client.readyState !== 'closed') { 206 | // @ts-ignore 207 | this.client.end() 208 | } 209 | } 210 | 211 | /** 212 | * Destroy Client 213 | */ 214 | validateClient() { 215 | // @ts-ignore 216 | return (!this.client.hadError && this.client.readyState === 'connected') 217 | } 218 | 219 | /** 220 | * Prepare database statement 221 | * @param {string} query - database query 222 | * @returns {any} - prepared statement object 223 | */ 224 | preparePromisified(query) { 225 | debug(`Query:`, query) 226 | // @ts-ignore 227 | return this.client.promisePrepare(query) 228 | } 229 | 230 | /** 231 | * Execute DB Statement in Batch 232 | * @param {any} statement - prepared statement object 233 | * @param {any} parameters - query parameters 234 | * @returns {Promise} - resultset 235 | */ 236 | statementExecBatchPromisified(statement, parameters) { 237 | statement.promiseExecBatch = this.util.promisify(statement.execBatch) 238 | return statement.promiseExecBatch(parameters) 239 | } 240 | 241 | /** 242 | * Execute DB Statement 243 | * @param {any} statement - prepared statement object 244 | * @param {any} parameters - query parameters 245 | * @returns {Promise} - resultset 246 | */ 247 | statementExecPromisified(statement, parameters) { 248 | statement.promiseExec = this.util.promisify(statement.exec) 249 | return statement.promiseExec(parameters) 250 | } 251 | 252 | /** 253 | * Load stored procedure and return proxy function 254 | * @param {string} schema - Schema name can be null 255 | * @param {string} procedure - DB procedure name 256 | * @returns {Promise} - proxy function 257 | */ 258 | async loadProcedurePromisified(schema, procedure) { 259 | if(!schema){ 260 | schema = await this.schemaCalc({schema: '**CURRENT_SCHEMA**'}, this) 261 | } 262 | let procedureMetaData = await this.fetchSPMetadata(this, {schema: schema, name: procedure}) 263 | let callString = '' 264 | procedureMetaData.forEach(() => { 265 | if(callString === ''){ 266 | callString += `?` 267 | }else { 268 | callString += `,?` 269 | } 270 | }) 271 | if(callString === ''){ 272 | callString += `?` 273 | } 274 | //console.log(callString) 275 | return this.preparePromisified(`CALL ${schema}."${procedure}"(${callString})`) 276 | } 277 | 278 | 279 | /** 280 | * Execute single SQL Statement and directly return result set 281 | * @param {string} sql - SQL Statement 282 | * @returns {Promise} - result set object 283 | */ 284 | execSQL(sql) { 285 | return new Promise((resolve, reject) => { 286 | this.preparePromisified(sql) 287 | .then((/** @type {any} */ statement) => { 288 | this.statementExecPromisified(statement, []) 289 | .then(results => { 290 | resolve(results) 291 | }) 292 | .catch(err => { 293 | reject(err) 294 | }); 295 | }) 296 | .catch((/** @type {any} */ err) => { 297 | reject(err) 298 | }) 299 | }) 300 | } 301 | 302 | /** 303 | * Call Database Procedure 304 | * @param {any} storedProc - stored procedure proxy function 305 | * @param {any} inputParams - input parameters for the stored procedure 306 | * @returns 307 | */ 308 | callProcedurePromisified(storedProc, inputParams) { 309 | return new Promise((resolve, reject) => { 310 | // @ts-ignore 311 | storedProc.exec(inputParams, (/** @type {any} */ error, /** @type {any} */ outputScalar, /** @type {string | any[]} */ ...results) => { 312 | 313 | // storedProc(inputParams, (error, outputScalar, ...results) => { 314 | if (error) { 315 | reject(error) 316 | } else { 317 | if (results.length < 2) { 318 | resolve({ 319 | outputScalar: outputScalar, 320 | results: results[0] 321 | }) 322 | } else { 323 | let output = {}; 324 | output.outputScalar = outputScalar; 325 | for (let i = 0; i < results.length; i++) { 326 | // @ts-ignore 327 | output[`results${i}`] = results[i] 328 | } 329 | resolve(output) 330 | } 331 | } 332 | }) 333 | }) 334 | } 335 | 336 | } 337 | 338 | --------------------------------------------------------------------------------