Skip to Content
Technical Articles

PostgreSQL persistence adapter for CAP (Node.js)

For the SAP Cloud Application Programming Model (CAP), SAP HANA (cloud) is the only officially supported first-class citizen for storing db artifacts in production.

At the same time, CAP is beautiful.

cap%20overview%20architecture

cap overview architecture

Because its’ core is open, avoids tech-stack lock-in, behaves non-intrusive and is platform agnostic: all key characteristics for enabling the framework to run ouside SAPverse.

Given that SAP HANA cloud is only available in SAP world (more specifically, in SAP Cloud Platform, SCP), there’s a contradiction to resolve – how do we get CAP to run outside of SAP?

cds-pg

On the persistence level, extending CAP to support a popular Open Source database is the first step to proverbial shake off SAP-inflicted technology restraints –
and the CAP community has taken the leap and created a PostgreSQL storage adapter named “cds-pg” (cds == “core data services”, pg == PostgreSQL).

cds-pg extends the official cds.Service-API by wrapping node-pg, a PostgreSQL client for Node.js.

The project has been set up so that all the groundwork is layed out:
the adapter fits in with @sap/cds (the Node.js module of CAP),
is ready to be included in CAP-projects and -most importantly-
is equiped code-wise so that anybody can contribute features to cds-pg easily.

contributing features

cds-pg at the time of this writing is in an alpha state. It supports basic SELECT statements mapping to OData GET for entitysets and single entities.

But the code base provides a standalone dockerized PostgreSQL server, an example CAP project connecting to it and several tests for yet missing features plus a detailed description of how to set up the development environment – so it is literally a matter of minutes (!) for anyone to set up shop and contribute to cds-pg.

We have even put in a SQLite-based variant of the example CAP project (npm run test:as-sqlite) so you can compare results between an SQLite- and the cds-pg-based persistence adapter 😀

the road ahead

make no mistake: cds-pg is nothing SAP as a company will officially support any time soon.

But it has the full consulting support of the CAP core development team, following the notion of striving towards making CAP itself open-source! 💪

So it is up to us as the CAP community 🧍‍♀️🧍🧍‍♂️ to pick up the playball, drive it across the playfield and score the metaphoric goal of getting all’em CRUD features into cds-pg – so we can use CAP with PostgreSQL in addition to SAP HANA-cloud, allowing productive applications to run on additional platforms than SCP.

So, calling out to you, the CAP community: fork, code, pull-request cds-pg. Lots!!!
(tech tl;dr for this:

# first, fork the repo: https://github.com/sapmentors/cds-pg 
git clone https://github.com/<you>/cds-pg 
cd cds-pg 
nvm use # lts/erbium 
npm i 
npm run test:pg:up-nobg # dockerized postgres 
./node_modules/.bin/jest --watch # morph into TDD mode 
code . # open vs code 
npm run test:as-sqlite # start sqlite-based version for result comparison
# pick some test.todo(...) or test.skip(...) from __tests__/odata.js 
# and implement functionality 
... 
# head over to gh for creating a PR # or use git request-pull from the cmd line :)

)

Authors

Volker%20Buzek Volker is the self-proclaimed “Head of bar and beverage consumption on the CAP Open Sourcing party”.
Gregor%20Wolf Gregor in many aspects is the voice of the CAP community and a CAP earlier-than-early adopter.

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.