{"analyzedAt":"2022-08-11T16:23:24.200Z","collected":{"metadata":{"name":"sap-hdb-promisfied","scope":"unscoped","version":"2.202208.2","description":"Promise wrapper for hdb without any dependency to @sap/hana-client","keywords":["promise","hdb","sap","hana","database"],"date":"2022-08-11T16:06:27.110Z","author":{"name":"jung-thomas"},"publisher":{"username":"jungsap","email":"thomas.jung@sap.com"},"maintainers":[{"username":"jungsap","email":"thomas.jung@sap.com"}],"repository":{"type":"git","url":"git+https://github.com/SAP-samples/hana-hdbext-promisfied-example.git"},"links":{"npm":"https://www.npmjs.com/package/sap-hdb-promisfied","homepage":"https://github.com/SAP-samples/hana-hdbext-promisfied-example#readme","repository":"https://github.com/SAP-samples/hana-hdbext-promisfied-example","bugs":"https://github.com/SAP-samples/hana-hdbext-promisfied-example/issues"},"license":"Apache-2.0","dependencies":{"@sap/xsenv":"^3.3.2","debug":"4.3.4","dotenv":"^16.0.1","hdb":"0.19.5"},"devDependencies":{"@types/debug":"^4.1.7","@types/node":"^18.7.1","@types/sap__xsenv":"^2.0.3"},"releases":[{"from":"2022-07-12T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":2},{"from":"2022-05-13T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":6},{"from":"2022-02-12T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":10},{"from":"2021-08-11T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":18},{"from":"2020-08-11T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":18}],"hasTestScript":true,"readme":"# Promisfied Wrapper around hdb\r\n\r\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)\r\n\r\n## Description\r\n\r\nWith the standard hdb module you use nested events and callbacks like this:\r\n\r\n```JavaScript\r\nlet client = req.db;\r\nclient.prepare(\r\n\t`SELECT SESSION_USER, CURRENT_SCHEMA \r\n\t    FROM \"DUMMY\"`,\r\n\t(err, statement) => {\r\n\t\tif (err) {\r\n\t\t\treturn res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`);\r\n\t\t}\r\n\t\tstatement.exec([], (err, results) => {\r\n\t\t\tif (err) {\r\n\t\t\t\treturn res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`);\r\n\t\t\t} else {\r\n\t\t\t\tvar result = JSON.stringify({\r\n\t\t\t\t\tObjects: results\r\n\t\t\t\t});\r\n\t\t\t\treturn res.type(\"application/json\").status(200).send(result);\r\n\t\t\t}\r\n\t\t});\r\n\t\treturn null;\r\n\t});\r\n```\r\n\r\nHowever 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):\r\n\r\n```JavaScript\r\nconst dbClass = require(\"sap-hdb-promisfied\")\r\nlet db = new dbClass(req.db)\r\ndb.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA \r\n\t\t\t\t            FROM \"DUMMY\"`)\r\n\t.then(statement => {\r\n\t\tdb.statementExecPromisified(statement, [])\r\n\t\t\t.then(results => {\r\n\t\t\t\tlet result = JSON.stringify({\r\n\t\t\t\t\tObjects: results\r\n\t\t\t\t})\r\n\t\t\t\treturn res.type(\"application/json\").status(200).send(result)\r\n\t\t\t})\r\n\t\t\t.catch(err => {\r\n\t\t\t\treturn res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`)\r\n\t\t\t})\r\n\t})\r\n\t.catch(err => {\r\n\t\treturn res.type(\"text/plain\").status(500).send(`ERROR: ${err.toString()}`)\r\n\t})\r\n```\r\n\r\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:\r\n\r\n```JavaScript\r\ntry {\r\n\tconst dbClass = require(\"sap-hdb-promisfied\")\r\n\tlet db = new dbClass(req.db);\r\n\tconst statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA \r\n\t\t\t\t            \t\t\t\t\t\t\tFROM \"DUMMY\"`)\r\n\tconst results = await db.statementExecPromisified(statement, [])\r\n\tlet result = JSON.stringify({\r\n\t\tObjects: results\r\n\t})\r\n\treturn res.type(\"application/json\").status(200).send(result)\r\n} catch (e) {\r\n\treturn res.type(\"text/plain\").status(500).send(`ERROR: ${e.toString()}`)\r\n}\r\n```\r\n\r\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:\r\n\r\n```JavaScript\r\ntry {\r\n\t    import dbClass from 'sap-hdb-promisfied'\r\n        let db = new dbClass(await dbClass.createConnectionFromEnv(dbClass.resolveEnv(null)))\r\n        const statement = await db.preparePromisified(`SELECT SESSION_USER, CURRENT_SCHEMA \r\n                                                     FROM \"DUMMY\"`)\r\n        const results = await db.statementExecPromisified(statement, [])\r\n        console.table(results)\r\n        db.destroyClient()\r\n    } catch (/** @type {any} */ err) {\r\n        console.error(`ERROR: ${err.toString()}`)\r\n    }\r\n```\r\n\r\n### Methods\r\n\r\nThe following hdb functions are exposed as promise-based methods\r\n\r\n```JavaScript\r\nprepare = preparePromisified(query)\r\nstatement.exec = statementExecPromisified(statement, parameters)\r\nloadProcedure = loadProcedurePromisified(hdbext, schema, procedure)\r\nstoredProc = callProcedurePromisified(storedProc, inputParams)\r\n```\r\n\r\nWe also have the simplified helper method to both prepare and execute a simple statement via one command:\r\n\r\n```JavaScript\r\nexecSQL(sql)\r\n```\r\n\r\nAnd finally there are static helpers\r\n\r\n```JavaScript\r\ncreateConnectionFromEnv(envFile)\r\ncreateConnection(options)\r\nresolveEnv(options)\r\nschemaCalc(options, db)\r\nobjectName(name)\r\n```\r\n\r\n## Requirements / Download and Installation\r\n\r\n* Install any supported version of Node.js on your development machine [https://nodejs.org/en/download/](https://nodejs.org/en/download/)\r\n\r\n* Install the code sample as a reusable Node.js module\r\n\r\n```shell\r\nnpm install -g sap-hdb-promisfied\r\n```\r\n\r\nOr you can leverage this module by just listing as requirement in your own project's package.json.\r\n\r\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)\r\n\r\n## Known Issues\r\n\r\nNone\r\n\r\n## How to obtain support\r\n\r\nThis project is provided \"as-is\": there is no guarantee that raised issues will be answered or addressed in future releases.\r\n\r\n## License\r\n\r\nCopyright (c) 2020 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."},"npm":{"downloads":[{"from":"2022-08-10T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":37},{"from":"2022-08-04T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":296},{"from":"2022-07-12T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":1036},{"from":"2022-05-13T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":3024},{"from":"2022-02-12T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":5346},{"from":"2021-08-11T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":5820}],"starsCount":0},"github":{"starsCount":10,"forksCount":7,"subscribersCount":9,"issues":{"count":13,"openCount":0,"distribution":{"3600":6,"10800":1,"32400":2,"97200":3,"291600":0,"874800":1,"2624400":0,"7873200":0,"23619600":0,"70858800":0,"212576400":0},"isDisabled":false},"contributors":[{"username":"mmicciolo-sap","commitsCount":1},{"username":"sahilkumar129","commitsCount":1},{"username":"btbernard","commitsCount":10},{"username":"jung-thomas","commitsCount":49},{"username":"larshp","commitsCount":1}],"commits":[{"from":"2022-08-04T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":1},{"from":"2022-07-12T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":3},{"from":"2022-05-13T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":7},{"from":"2022-02-12T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":16},{"from":"2021-08-11T00:00:00.000Z","to":"2022-08-11T00:00:00.000Z","count":29}]},"source":{"files":{"readmeSize":4946,"testsSize":11131,"hasShrinkwrap":true}}},"evaluation":{"quality":{"carefulness":0.71,"tests":0.6,"health":1,"branding":0},"popularity":{"communityInterest":31,"downloadsCount":1008,"downloadsAcceleration":8.085730593607305,"dependentsCount":0},"maintenance":{"releasesFrequency":1,"commitsFrequency":0.9,"openIssues":1,"issuesDistribution":1}},"score":{"final":0.6208811159862562,"detail":{"quality":0.8083361703923992,"popularity":0.08109848834950383,"maintenance":0.9999879827034572}}}