{"id":20484457,"url":"https://github.com/sap-samples/hana-hdbext-promisfied-example","last_synced_at":"2025-05-12T17:23:43.135Z","repository":{"id":41611287,"uuid":"256634841","full_name":"SAP-samples/hana-hdbext-promisfied-example","owner":"SAP-samples","description":"Example of how to use @sap/hdbext (standard node.js SAP HANA interface) via a promisfied wrapper.","archived":false,"fork":false,"pushed_at":"2025-03-13T18:07:21.000Z","size":497,"stargazers_count":14,"open_issues_count":0,"forks_count":6,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-12T17:23:34.020Z","etag":null,"topics":["hana-xs","hdbext","owner-jung-thomas","promise-wrapper","sample","sample-code","sap-hana"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SAP-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-18T00:01:23.000Z","updated_at":"2025-04-04T03:37:25.000Z","dependencies_parsed_at":"2024-01-02T19:23:52.506Z","dependency_job_id":"91ae7923-a49d-48be-9d66-160f3979431c","html_url":"https://github.com/SAP-samples/hana-hdbext-promisfied-example","commit_stats":{"total_commits":66,"total_committers":5,"mean_commits":13.2,"dds":"0.19696969696969702","last_synced_commit":"2ecec8713113550450f75c28d6b41bc1cc50684e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fhana-hdbext-promisfied-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fhana-hdbext-promisfied-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fhana-hdbext-promisfied-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fhana-hdbext-promisfied-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAP-samples","download_url":"https://codeload.github.com/SAP-samples/hana-hdbext-promisfied-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253785193,"owners_count":21963926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hana-xs","hdbext","owner-jung-thomas","promise-wrapper","sample","sample-code","sap-hana"],"created_at":"2024-11-15T16:22:34.375Z","updated_at":"2025-05-12T17:23:43.124Z","avatar_url":"https://github.com/SAP-samples.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Promisfied Wrapper around @sap/hdbext and [hdb](hdb/README.md)\n\n[![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)\n\n## Description\n\nWith the standard @sap/hdbext you use nested events and callbacks like this:\n\n```JavaScript\nlet client = req.db;\nclient.prepare(\n `SELECT SESSION_USER, CURRENT_SCHEMA \n     FROM \"DUMMY\"`,\n (err, statement) =\u003e {\n  if (err) {\n   return res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`);\n  }\n  statement.exec([], (err, results) =\u003e {\n   if (err) {\n    return res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`);\n   } else {\n    var result = JSON.stringify({\n     Objects: results\n    });\n    return res.type(\"application/json\").status(200).send(result);\n   }\n  });\n  return null;\n });\n```\n\nHowever 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):\n\n```JavaScript\nconst dbClass = require(\"sap-hdbext-promisfied\")\nlet db = new dbClass(req.db)\ndb.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA \n                FROM \"DUMMY\"`)\n .then(statement =\u003e {\n  db.statementExecPromisified(statement, [])\n   .then(results =\u003e {\n    let result = JSON.stringify({\n     Objects: results\n    })\n    return res.type(\"application/json\").status(200).send(result)\n   })\n   .catch(err =\u003e {\n    return res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`)\n   })\n })\n .catch(err =\u003e {\n  return res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`)\n })\n```\n\nOr 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:\n\n```JavaScript\ntry {\n const dbClass = require(\"sap-hdbext-promisfied\")\n let db = new dbClass(req.db);\n const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA \n                       FROM \"DUMMY\"`)\n const results = await db.statementExecPromisified(statement, [])\n let result = JSON.stringify({\n  Objects: results\n })\n return res.type(\"application/json\").status(200).send(result)\n} catch (e) {\n return res.type(\"text/plain\").status(500).send(`ERROR: ${e.toString()}`)\n}\n```\n\nThere 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:\n\n```JavaScript\ntry {\n    const dbClass = require(\"sap-hdbext-promisfied\")\n    let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null)))\n    const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA \n                                                     FROM \"DUMMY\"`)\n    const results = await db.statementExecPromisified(statement, [])\n    console.table(results)\n} catch (e) {\n    console.error(`ERROR: ${err.toString()}`)\n}\n```\n\n### Methods\n\nThe following @sap/hdbext functions are exposed as promise-based methods\n\n```JavaScript\nprepare = preparePromisified(query)\nstatement.exec = statementExecPromisified(statement, parameters)\nloadProcedure = loadProcedurePromisified(hdbext, schema, procedure)\nstoredProc = callProcedurePromisified(storedProc, inputParams)\n```\n\nWe also have the simplified helper method to both prepare and execute a simple statement via one command:\n\n```JavaScript\nexecSQL(sql)\n```\n\nAnd finally there are static helpers\n\n```JavaScript\ncreateConnectionFromEnv(envFile)\ncreateConnection(options)\nresolveEnv(options)\nschemaCalc(options, db)\nobjectName(name)\n```\n\n## Requirements / Download and Installation\n\n* Install Node.js version 12.x or 14.x on your development machine [https://nodejs.org/en/download/](https://nodejs.org/en/download/)\n\n* @sap Node.js packages have moved from [https://npm.sap.com](https://npm.sap.com]) to the default registry \u003chttps://registry.npmjs.org\u003e. As future versions of @sap modules are going to be published only there, please make sure to adjust your registry with:\n\n```shell\nnpm config delete @sap:registry\n```\n\n* Install the code sample as a reusable Node.js module\n\n```shell\nnpm install -g sap-hdbext-promisfied\n```\n\nOr you can leverage this module by just listing as requirement in your own project's package.json.\n\nFinally 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)\n\n## Known Issues\n\nNone\n\n## How to obtain support\n\nThis project is provided \"as-is\": there is no guarantee that raised issues will be answered or addressed in future releases.\n\n## License\n\nCopyright (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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fhana-hdbext-promisfied-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsap-samples%2Fhana-hdbext-promisfied-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fhana-hdbext-promisfied-example/lists"}