cancel
Showing results for 
Search instead for 
Did you mean: 

database module under XS Advanced: SQL Update possible during build?

0 Kudos

Hi,

under HANA XS Advanced, i'm working on a MTA project. I want to automatically manipulate the entries in one of my database tables during the build of the database module of the project. More specifically, i want to update the entries after they have been inserted - using hdbtabledata - but before the module is used by other modules. How can this be done?

Thanks!

Accepted Solutions (0)

Answers (2)

Answers (2)

gregorw
Active Contributor

You can adjust the package.json of your db module and call your own script after the execution of:

"start": "node node_modules/@sap/hdi-deploy/deploy.js",
0 Kudos

Hi Gregor,

i'm afraid i need some further directions since i'm rather new to js. I changed my package.json to:

"start": "node node_modules/@sap/hdi-deploy/deploy.js",
"poststart": "echo start done",

But when i choose "Build" in Web IDE, my script does not seem to get called. Is it called only on Deployment of the complete mtar?

Next step would be something like:

"start": "node node_modules/@sap/hdi-deploy/deploy.js",
"poststart": "node prep_db_tables.js",

In my script, do i have access to $.hdb like in my Node.js module?

Thanks!

gregorw
Active Contributor
0 Kudos

Hi Stefan,

when you add @sap/hana-client as a dependency you should have no issues connecting to the DB using the credentials provided via the environment. @sap/xsenv helps you to read this values.

Have you tried:

"start": "node node_modules/@sap/hdi-deploy/deploy.js && echo 'Start done'"

?

Best regards
Gregor

0 Kudos

Hi Gregor,

"... && echo 'Start done'" gives me an error "Build command failed: hdi-build operation failed: The start command must not contain \\' or '!"

Interesting enough: I do not get this error with my above trial with "poststart".

I just omited the single quotes and the project builds!

Unfortunately, i still don't see any effects of my start script. I would have expected to see the "Start done" somewhere in the Web IDE Console.

Furthermore, i created a stand-alone-script named "prep_db_tables.js" which uses @sap/hana-client to do an SQL-update on one of my tables. So far, i have not yet figured out how to use @sap/xsenv to get the credentials, but for a first test i simply put them in manually. The script works and the db entry gets updated. But when i put the same script in my Web IDE project, connect it to the start command via package-json and start the build process, the db entry does not get updated.

Where am i going wrong?