Created
January 27, 2018 11:28
-
-
Save jasper07/c9e6d173ec6fbfc2d2f8c51c8528044e to your computer and use it in GitHub Desktop.
SAP HANA Database Client for Node working with ES6 Async Await and promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var util = require('util'); | |
// var async = require('async'); | |
var client = require('./client'); | |
var fields = ['SCHEMA_NAME || \'.\' || TABLE_NAME as TABLE']; | |
var sql = util.format('select top 5 %s from TABLES', fields.join(',')); | |
const connect = async () => | |
await client.connect(); | |
const executeAndfetchRows = () => | |
new Promise((resolve, reject) => | |
client.exec(sql, (err, rows) => resolve(rows))) | |
const disconnect = (rows) => | |
new Promise((resolve, reject) => | |
client.disconnect((err) => err ? reject(err) : resolve(rows))) | |
const getSQLResults = async () => | |
await connect().then(executeAndfetchRows).then(disconnect); | |
getSQLResults().then((aRows) => | |
console.log(util.inspect(aRows, { | |
colors: true | |
})) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment