viernes, 10 de enero de 2014

MeteorJS and SAP HANA

If you thought that I was going to learn MeteorJS and not try to link with SAP HANA...then you were dead wrong -;)

Of course...I'm far from being a good Meteor please bear with me -:( I'm also not very good at know...this is just me playing around -:)

So...let's begin...there's a lot of ways that we can use to connect Meteor and SAP HANA...but...what if we can somehow do it with a native connection?

If you haven't visit SAP Developers on GitHub yet...I recommend you to do it...we have some really nice Open Source projects in there... there you will find a hidden gem simply called node-hdb which is course...a NodeJS native connector for SAP HANA...awesome, huh? will ask...why does NodeJS has to do with Meteor? Easy...Meteor uses NodeJs in the background...

Checking the web...I found this awesome Meteor Hack called Complete NPM integration for Meteor which is just allows us to include NodeJS packages in the underlying NodeJS service of our Meteor installation...

Simply do this...

Getting node-hdb into Meteor
npm install -g meteor-npm
cd "your_project"

This will create an "npm" folder into your create a file called packages.json in your root folder...

 "hdb": "0.2.0"

With that...we're ready to rock with Meteor -;)

First...let's do the html part...

  <title>SAP HANA and MeteorJS</title>

  {{> CallHANA}}

<template name="CallHANA">
<H1>Calling SAP HANA from MeteorJS</H2>
     <TH>Country From</TH><TH>City From</TH>
     <TH>Airport From</TH><TH>Country To</TH>
     <TH>City To</TH><TH>Airport To</TH>
 {{#each Spfli}} 

Then...create two called "server" and the other called "client"...

Inside the "server" folder create a file called "HANA_TestServer.js"

var myjson = [];

    'CallHANA': function CallHANA() {
  hdb    = Meteor.require('hdb');
    client = hdb.createClient({
    host     : '',
    port     : 30015,
    user     : 'SYSTEM',
    password : 'XXXXXX'

  client.connect(function (err) {
     if (err) {
       return console.error('Connect error', err);
      client.exec('select top 10 * from SFLIGHT.SPFLI', function (err, rows) {
       if (err) {
          return console.error('Execute error:', err);
        var count = Object.keys(rows).length
        for(var i=0;i<count;i++){
  return myjson;

Then inside the "client" folder create a file called ""HANAClient.js"...

 Meteor.startup(function () {"CallHANA", function (error, result) {
             Session.set("myjson", result);

    Template.CallHANA.Spfli = function () {
     row = Session.get("myjson");
     return row;

With that ready...simply call up your meteor application and after you refresh your page...I need to work on the reactivity part -:( I'm sure a single button calling the function will do the trick...but I'm tired and I'm lazy...The result from the query will be shown -;)

Not that fancy I know...but for the first step...I guess it's good enough -;)


Developer Empowerment and Culture.

No hay comentarios: