shwetasrivastava / Ohana

SAP HANA ORM for Node.js

Home Page:https://shwetasrivastava.github.io/Ohana/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use for HDI in XSA

Yaroslav-BV opened this issue · comments

Hello, Shweta.

Can this ORM be used to access the HDI container in an XS Advanced application?

My project has a Node.js module that runs an Express.js server. The MTA.yml of this module must contain the HDI container. I tried to use your ORM to access this HDI, but geting error: Could not find table/view <my_table_name> in schema <username_is_substituted_here>. Instead of the scheme passed to the connection, the username is substituted

My code looks like this:

var express = require("express");
var xsenv = require("@sap/xsenv");
var {connection, ohana} = require('ohana-node-orm');

var app = express();
var portServer = process.env.PORT || 3000;

var services = xsenv.getServices({
  hana: { tag: "hana" }
});

const { port, host, user, password, schema } = services.hana;

const connectionParams = {
    host: host,
    port: port,
    user: user,
    password: password,
    dbname: schema
};

const orders = new ohana('Orders');

app.get('/hana', async (req, res) => {
	try {
	    var results = await orders.find();
	    res.json(results);
	} catch(err) {
	    res.json({message: "Error model Orders", error: err})
	}
});

function startServer() {
    connection.connect(connectionParams)
	.then((success) => {
	     console.log('Connected');
	})
	.catch((error) => {
	     console.log('Error', error);
	});
	
    app.listen(portServer, function () {
	  console.log("App listening on port " + port);
    });
}

startServer();

Tell me please.

Best regards, Yaroslav

Hello Yaroslav,

Well, with what I understood you are to trying to develop this node app with WEB IDE most probably where we have MTL.yml available. Basically this package works well if you develop it locally in your visual studio, I am not very sure of issues that it may create while using it from SAP WEB IDE. However, you can take this as an issue and may contribute.

Regards,
Shweta

I solved the problem. The scheme must be passed to the parameters for connection via the currentSchema property. This property is inherited from @sap/hana-client. Then we managed to get the result.

/* ...another code from my comment above... */

const { port, host, user, password, schema } = services.hana;

const connectionParams = {
    host: host,
    port: port,
    user: user,
    password: password,
    currentSchema: schema // Here
};

/* ...another code from my comment above... */

One more nuance:
If you work through the WEB IDE, you must pass the table name in double quotes

const orders = new ohana('Orders'); // bad
const orders = new ohana('"Orders"'); // good

Shweta, thanks for the ORM for HANA. I hope this project will develop further

@Yaroslav-BV - Well , I am really glad to know that it worked, thanks for sharing the solution to the issue. I hope you will be able to use this package to make your developments quick and easy.

Regards,
Shweta