2 weeks ago
Hello all,
we are using CAP service however we would like to change dynamically the datastore where data are located.
example:
HDI1: tableA
HDI2: tableA
in our CAP service we have defined entity for table A as cds.persistence.exists true annotation. We would like to have a service:
I have tried below code, looks like it is working properly:
module.exports = class TestService extends cds.ApplicationService {
async init() {
this.on('*', async (_req) => {
let db:cds.Service;
if (!cds.env?.requires[envJson.schema]) {
cds.env.requires[envJson.schema] = {}
// Here we will get HANA container credentials from MDS service and connect to it
db = await cds.connect.to(envJson.schema, { kind: "hana", impl: "@sap/cds-hana", credentials: envJson });
} else {
db = cds.services[envJson.schema];
}
return await db.run(_req.query);
});
return super.init() ;
}
};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.