Hello folks,
I'm building an app on Cloud Platform (CF) using Node.js/Express. This thing has a /db module containing a entity definition (books-model.cds) and /srv that runs a node.js app on server.js that should read data declared on db module.
According to this documentation the package @sap/cds should help me do exactly that, using the statements below:
cds.importEntities([
{ $entity: "xsds.test.cds::ds_test.e1" },
{ $entity: "xsds.test.cds::ds_test.e2",
$fields: {
a: { $association: "xsds.test.cds::ds_test.e2",
$viaBacklink: "b" }
}
}
], callback);
function callback(error, entities) {
var E1 = entities["xsds.test.cds::ds_test.e1"];
var E2 = entities["xsds.test.cds::ds_test.e2"];
// ...
}
Thing is, @sap/cds module v2.10 doesn't seem to think that it is responsible for doing that. This version only handles the build and deployment of .cds files (to hdbcds et etc).
In a old version of this module, before going to npm repository, it was called "sap-cds" and it did provided this .importEntity method.
Does someone know what would be the equivalent of sap-cds on npm.sap.com, or even if it exists?
So far, I'm able to interact with the database using @sap/xsenv and @sap/hdbext.
import xsenv = require('@sap/xsenv') import hdbext = require('@sap/hdbext')
const services = xsenv.getServices({ hana:'plcockpit-hdi' })
express.use('/', hdbext.middleware(services.hana))
express.get('/', (req, res) => {
req.db.exec('SELECT * FROM \"com.acme::MyLibrary.Books\"', function (err, rows) {
res.json({
result: JSON.stringify(rows[0])
})
})
})
(Code is a simplified version of the original)
Although it works, I would like to know if is there a more "high-level" api to interact with the CDS layer.
Thanks
Request clarification before answering.
Hi Ulysses,
I'm doing similar things in CF environment like you.
And I'm referencing below document.
SAP Cloud Application Programming Model - Javascript API
I want to connect to the HANA DB at CF in my node.js module but I can't.
const cds = require('@sap/cds');
// examples in the document
const srv = await cds.connect.to('db');
const { Books, Authors } = srv.entities('my.booskhop'); // undefined
const model = srv.model; // undefinedDo you have any idea?
Thank you,
JaeHyeon Lee.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.