Skip to content

Instantly share code, notes, and snippets.

@jasper07
Created January 27, 2018 11:28
Show Gist options
  • Save jasper07/c9e6d173ec6fbfc2d2f8c51c8528044e to your computer and use it in GitHub Desktop.
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
'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