@cap-js/postgres
The PostgreSQLPostgreSQLA relational database. For CAP it is the production database when the answer is not HANA, reached through an adapter that translates CDS queries into its SQL. database service — the production option for running CAP off HANA, sharing the base service with the other three.
Facts
Where it sits
Who is behind it
In the atlas: maintains 34@cap-jsmaintainerJohannes VogtContributes to this
In the atlas: maintains 1, contributes to 28, wrote 10@AkatuoroArley Triana MorinContributes to this
In the atlas: contributes to 9, wrote 1@arleytmAndreas SchmidtContributes to this
In the atlas: contributes to 6@aschmidt93Bob den OsContributes to this
In the atlas: contributes to 13@BobdenOsAndre MeyeringContributes to this
In the atlas: contributes to 10@bugwelleCAP BotContributes to this
In the atlas: contributes to 5@cap-botsChristian GeorgiContributes to this
In the atlas: maintains 1, contributes to 53@chgeoChristian SchüringsContributes to this
In the atlas: contributes to 25@cschueringsDaniel HutzelContributes to this
In the atlas: contributes to 32, wrote 3@danjoaDaniel O'GradyContributes to this
In the atlas: contributes to 10@daogrady35 contributors
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 1, 2, 3A cds-plugin is used with SAP CAP materials, or an artifact is explicitly identified as a CAP plugin or application.
- § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
- § 2 Intellectual Property. The agreement retains SAP's rights in the covered materials and limits making APIs, tools or software available to third parties, while preserving ownership of customer applications subject to SAP's underlying rights.
- § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
Also, from Database connectors§ 1: The connector itself does not decide the licence boundary. Section 1 makes the destination and purpose of extraction relevant, including the scoped exception for interoperability with an SAP product.
What it declares
Every artifact
- Type
- CDS plugin
- Origin
- By SAP
As a CDS plugin
- Declared for
- ^10
- Distributed through
- npm
Connections
PostgreSQL adapter for SAP CDS from the SAP Mentors community
Connecting a data model and its queries to a database
Managed PostgreSQL from the hyperscaler via a BTP service binding
A relational database. For CAP it is the production database when the answer is not HANA, reached through an adapter that translates CDS queries into its SQL.
Monorepo of CAP's SQL database services
Download
Install
npm add @cap-js/postgresDerived from the package name. No recipe recorded; the README has the configuration.
Learn more
- SAP CAP With Prostgres Serice in BTPSAP CAP With Prostgres Serice in BTPA step-by-step walkthrough of a CAP bookshop project on @cap-js/postgres, provisioning PostgreSQL on SAP BTP, hyperscaler option's trial plan through mta.yaml, building the MTA archive and deploying it to Cloud Foundry by hand, then inspecting the deployed database with pgAdmin over an SSH tunnel. It updates an earlier post by Mike Zaschka on the same topic to the package CAP now ships by default, though the manual build-and-deploy sequence it shows predates cds up folding those steps into one command by a day.satya-dev, published 2025-03-30satya-dev, SAP Community
- Run and Deploy SAP CAP (Java) with PostgreSQL using Official Database Adapter @cap-js/postgresRun and Deploy SAP CAP (Java) with PostgreSQL using Official Database Adapter @cap-js/postgresThe post that records a handover. The author's earlier writing relied on the community projects cds-pg and cds-dbm; this one states that both were deprecated in favour of the official PostgreSQL support arriving with @sap/cds 7, and rewrites the path around @cap-js/postgres. For CAP Java it takes a different route to the initial schema.sql than the Node.js case, and it is candid that automatic schema deployment is convenient but not always what you want. Dated evidence for why two artifacts here went quiet.shanthakumar_krishnaswamy, published 2023-08-02shanthakumar_krishnaswamy, SAP Community
- Run and Deploy CAP with PostgreSQL on SAP BTP Cloud Foundry (Node.js)Run and Deploy CAP with PostgreSQL on SAP BTP Cloud Foundry (Node.js)The deployment half of the pair, two weeks after the local one, and superseded the same way: it carries the same banner directing readers to @cap-js/postgres and the official documentation. The two together are the community PostgreSQL path as it stood before the core absorbed it.published 2020-11-30Mike Zaschka, SAP Community
1 more
- Getting started with CAP on PostgreSQL (Node.js)Getting started with CAP on PostgreSQL (Node.js)Running CAP on PostgreSQL locally in 2020, when doing so meant the community packages cds-pg and cds-dbm. It now opens with a banner the author added later: @sap/cds 7.0.0 has native PostgreSQL support, use @cap-js/postgres instead, with a pointer to a step-by-step guide for it. Worth having for that banner as much as for the content — a post that tells you not to follow it is a dated fact about where the answer moved.published 2020-11-16Mike Zaschka, SAP Community
- v3.0.0
The service requires @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, cap 10.
Makes stale:Installing the current @cap-js/postgres into a project on @sap/cds 9.
2 earlier
- v2.0.1
The service no longer replaces PostgreSQL
?placeholders in queries, and thestream_compatmode was removed.Makes stale:Native SQL passed to the service with
?placeholders, and configurations that setstream_compat. - v2.0.0
The peer dependency moved to @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, cap 9 and
@cap-js/db-service2, and database constraint errors are passed through unfiltered.Makes stale:Setups pairing @cap-js/postgres with @sap/cds 8 or earlier on the current major.
Where it sits in your app
Download
README
quoted from cap-js/cds-dbs under Apache-2.0, readCDS database service for Postgres
Welcome to the PostgreSQL database service for SAP Cloud Application Programming Model Node.js, based on streamlined database architecture and pg driver .
Setup
In general, all you need to do is to install the database package, as follows:
npm add @cap-js/postgres
Learn more about setup and usage in the respective database guide.
Support
This project is open to feature requests/suggestions, bug reports etc. via GitHub issues.
Contribution
Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.
Versioning
This library follows Semantic Versioning. All notable changes are documented in CHANGELOG.md.
Code of Conduct
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.
Licensing
Copyright 2023 SAP SE or an SAP affiliate company and cds-dbs contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.
migration guide from cds-pg to @cap-js/postgres
@cap-js/postgres works as a drop-in replacement for cds-pg.
However, some preliminary checks and cleanups help:
- for using the BTP Postgres Hyperscaler as database,
- know that the credentials are picked up automatically by from the enviornment (
VCAP_SERVICES.postgres) - the service binding label is
postgresql-db cds-dbmis replaced by a hand-crafted "db-deployer" app → see below
- know that the credentials are picked up automatically by from the enviornment (
- your local
package.json: you can safely remove the entrycds.requires.postgrespreviously mandatory forcds-pg - recommendation: set the env var
DEBUG=sqlduring local development to see DB-level output from PostgreSQL
schema migration
@cap-js/postgres brings the same schema evolution capabilities to PostgreSQL known from SAP HANA and SQLite.
Enabling schema migration in an existing cds-pg-based project consists of generating and deploying a "csn-snapshot" of your database structure.
local development
First, set a basis for the evolution
$> cds deploy --model-only
→ this will create the table cds_model laying the foundation for the schema migration
Subsequent deployments can then re-use the standard deploy mechanism via $> cds deploy
On BTP, Cloud Foundry environment
The above "csn-snapshots" can be implemented via the mtar-based approach. At the same time, the same mtar can be used for subsequent PostgreSQL deployments (with schema evolution).
Two major steps in addition to enabling the schema evolution are included in this mtar.
- create local folder
deployer(any name works) - in
deployer, create apackage.jsoncontaining
...
"//npm run migrate": "only one-time!",
"migrate": "cds deploy --model-only",
"//npm run deploy": "subsequent deployments",
"deploy": "cds deploy"
...
- add a section to your
/mta.yamldenoting thedeployerdirectory as a standalone application that runs one-time
- name: pg-db-deployer
type: custom
path: deployer
parameters:
buildpacks: nodejs_buildpack
no-route: true
no-start: true
disk-quota: 2GB
memory: 512MB
tasks:
- name: migrate
command: npm run migrate
# # for subsequent deployments
# - name: deploy
# command: npm run deploy
disk-quota: 2GB
memory: 512MB
build-parameters:
before-all:
custom:
- npm i
# generate the "csn-snapshot" - only necessary for one-time migration,
# can be commented out on subsequent deployments
- cds compile '*' -2 json > deployer/schema.csn
ignore: ["node_modules/"]
requires:
- name: pg-database
resources:
- name: pg-database
parameters:
path: ./pg-options.json
service: postgresql-db
service-plan: trial # change to yours!
skip-service-updates:
parameters: true
service-tags:
- plain
type: org.cloudfoundry.managed-service
migration points to consider
mixed-case identifiers
even though column names that are not double-quoted are folded to lowercase in PostgreSQL (yourName -> yourname, "yourName" -> yourName),
you can use the mixed case definitions from your .cds files to reference them.
example: brewery_id on DB level -> brewery_ID on CDS level
formerly w/ cds-pg you had to follow the DB level: SELECT.from(Beers).columns('brewery_id').groupBy('brewery_id')
now, re-use the CDS definitions: SELECT.from(Beers).columns('brewery_ID').groupBy('brewery_ID')
So please adjust your CQL statements accordingly.
timezones (potential BREAKING CHANGE)
any date- + time-type will get stored in UTC without any timezone identifier in the actual data field.
CAP's inbound- and outbound adapters take care of converting incoming and outgoing data from/to the desired time zones.
So when a datetime comes in being in an ISO 8601 compatible format
2009-01-01T15:00:00+01:00 (15:00:00 on January 1 2009 in Vienna (CEST))
will get stored as
2009-01-01T13:00:00 (13:00:00 on January 1 2009 in UTC).
Please be aware of that concept and rely on the client to parse UTC in your desired timezone (format).
cds.DatabaseService consumption
InsertResult now does only return the affected rows and their IDs.
const entries = [
{ name: 'Beer1', /* ... */ },
{ name: 'Beer2', /* ... */ },
{ name: 'Beer3', /* ... */ }
]
const insertResult = await cds.run(INSERT.into(Beers).entries(entries))
expect(insertResult.affectedRows).to.equal(3)
const beers = [...insertResult] //> this calls the [Symbol.iterator] method of the insert result
// beers:
// [
// { ID: "f81d7ee5-922b-48a1-a12a-a899b8594c99" },
// { ID: "ddda7f8e-e26b-430f-a80c-ac2c7df29510" },
// { ID: "7228c40f-0046-4f53-8a2b-3d55ad825f59" }
// ]
In cds-pg, we additionally surfaced the entire inserted dataset.
// continuing after the insert of the above example:
// const insertResult = await cds.run(INSERT.into(Beers).entries(entries))
// this works NO MORE - see above
const beers = insertResult.results
expect(beers.length).toStrictEqual(3)
expect(beers[0].ID).toMatch(uuidRegex)
expect(beers[0].createdAt.toISOString()).toMatch(timestampRegex)
expect(beers[0].modifiedAt.toISOString()).toMatch(timestampRegex)
So please adjust your runtime coding accordingly.
History
Dependencies 1
Notes
Dependencies
- The following workspace dependencies were updated
- dependencies
- @cap-js/db-service bumped from ^3.1.1 to ^3.1.2
- dependencies
Dependencies 1
Notes
Dependencies
- The following workspace dependencies were updated
- dependencies
- @cap-js/db-service bumped from ^3.1.0 to ^3.1.1
- dependencies
- The following workspace dependencies were updated
Features 1, Fixes 1, Dependencies 1
Breaking 1, Features 1, Dependencies 1
Dependencies 1
Notes
Dependencies
- The following workspace dependencies were updated
- dependencies
- @cap-js/db-service bumped from ^2.9.0 to ^2.10.0
- dependencies
- The following workspace dependencies were updated
Dependencies 1
Notes
Dependencies
- The following workspace dependencies were updated
- dependencies
- @cap-js/db-service bumped from ^2.8.0 to ^2.8.1
- dependencies
- The following workspace dependencies were updated
Dependencies 1
Notes
Dependencies
- The following workspace dependencies were updated
- dependencies
- @cap-js/db-service bumped from ^2 to ^2.6.0
- dependencies
- The following workspace dependencies were updated
Features 1, Fixes 4
Notes
Added
Fixed
Features 1
Notes
Added
cds buildis now natively supported in@cap-js/postgres. Thus, acds buildwill automatically generate deployment artifacts for Postgres-enabled projects.
Features 1, Fixes 2
Notes
Added
- Reduced the usage of
is not distinct [not] from. #157
Fixed
- Reserved words are now used to automatically escape reserved words which are used as identifier. #178
- Remove column count limitation. #150
- Reduced the usage of
Features 1, Changed 1, Fixes 4
Notes
Added
- Connectivity to Azure PostgreSQL.
Fixed
- Order by collation waterfall:
- ICU
- best-effort mapping (
xx->xx_YY, wherexx_YYis the first match) - without collation
- More stable configuration of
schema_evolution = 'auto'. - Log
hostnamepreferrably during deployment. - Allow overriding of pool configuration.
Changed
- Session context variables are set as lower case instead of upper case.
Features 1, Changed 1
Notes
Added
pgprofile as mentioned in documentation
Changed
- Updated minimum required version of
@cap-js/db-service
Others providing
Compare all 22 on the Database connectors page →- cds-pgcds-pgA PostgreSQL adapter for SAP CDS, built by the SAP Mentors community, which gave CAP a Postgres persistence option years before @cap-js/postgres shipped.independent, capPostgreSQL adapter for SAP CDS from the SAP Mentors community
- SAP HANA CloudSAP HANA CloudThe managed database under most of this: CAP's default target, the store Datasphere and Analytics Cloud sit on, and a service with plans and components.sap official, btpManaged SAP HANA database service on BTP
- PostgreSQL on SAP BTP, hyperscaler optionPostgreSQL on SAP BTP, hyperscaler optionA managed PostgreSQL from the underlying hyperscaler — AWS, Azure, Google Cloud or Alicloud — consumed through a BTP service binding.sap official, btpManaged PostgreSQL from the hyperscaler via a BTP service binding
- com.sap.cds:cds-feature-hanacom.sap.cds:cds-feature-hanaThe CAP Java feature that wires a Maven application to SAP HANA Cloud, the production default among CAP's supported databases.sap official, capSAP HANA Cloud datasource for CAP Java applications
- com.sap.cds:cds-feature-jdbccom.sap.cds:cds-feature-jdbcConnects the CAP Java runtime to JDBC databases through the CDS4j JDBC runtime: H2 and SQLite, which capire names for local development and CI tests rather than enterprise use.sap official, capJDBC runtime for H2 and SQLite in CAP Java
- com.sap.cds:cds-feature-postgresqlcom.sap.cds:cds-feature-postgresqlThe CAP Java feature that wires a Maven application to PostgreSQL as its datasource beside SAP HANA, with limitations capire lists: schema evolution first, and no multitenancy or extensibility yet.sap official, capPostgreSQL datasource for CAP Java applications
- com.sap.cds:cds-services-bomcom.sap.cds:cds-services-bomThe Maven bill of materials for CAP Java, pinning every com.sap.cds module in a release, from the API and core runtime to the Spring Boot starters and the CQN engine, to the same version.sap official, capMaven bill of materials pinning CAP Java module versions
- @cap-js/db-service@cap-js/db-serviceThe base every CAP database service is built on: the shared query translation and pooling that SQLite, PostgreSQL and HANA specialise rather than reimplement.sap official, capBase service shared by CAP's SQLite, PostgreSQL and HANA services
- @cap-js/hana@cap-js/hanaThe HANA database service — the production default, on the same streamlined architecture as the SQLite and PostgreSQL services.sap official, capSAP HANA database service for CAP
- @cap-js/sqlite@cap-js/sqliteThe SQLite service, in memory during the inner loop — which is why a CAP project runs before anyone has provisioned a database.sap official, capSQLite database service for CAP, in memory during development
- cap-postgres-btp-connectivitycap-postgres-btp-connectivityConnects a CAP Node.js application to a PostgreSQL database that is not publicly reachable, tunnelling through BTP Connectivity and the Cloud Connector.independent, capTunnels CAP Node.js to a private PostgreSQL via Cloud Connector
- cds-mongodbcds-mongodbMongoDB as a native CAP database service, through Mongoose — CQN reads and writes, managed associations as ObjectId references, $expand resolved by populate, and cds deploy --to mongoose.independent, capMongoDB as a CAP database service through Mongoose
- @cds-pgroll/postgres@cds-pgroll/postgresThe destructive half of PostgreSQL schema evolution — DROP and RENAME, which CAP's own schema_evolution: alter will not perform — driven from the command line beside @cap-js/postgres.independent, capCLI for DROP and RENAME schema changes beside @cap-js/postgres
- @neoimpulse/cap-js-restore-model-defined-types@neoimpulse/cap-js-restore-model-defined-typesA CAP plugin that casts values back to the types the CDS model declares after a READ, for the entities you name, where the database driver returned them as strings.independent, capCAP plugin casting read values back to CDS model types
- @quadrio/cds-db2@quadrio/cds-db2A DB2 adapter for CDS, so a CAP model can be deployed to and served from DB2, last released July 2023 and still on npm while the repository it was published from has been deleted.independent, capDB2 adapter for CDS
- @sap/cds-hana@sap/cds-hanaThe SAP Cloud Application Programming Model's database adapter for SAP HANA, the package a CAP project adds to run its model on a SAP HANA database.sap official, capDatabase adapter for SAP HANA in CAP
- @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, capCAP Node.js runtime
- @sap/hana-client@sap/hana-clientSAP's own Node.js driver for SAP HANA: connect, run SQL and prepared statements, synchronously, through callbacks or as promises, over native client libraries npm installs per platform.sap official, btpSAP's Node.js driver for SAP HANA
- SAP HANASAP HANASAP’s relational database platform, which stores application data and executes SQL and SQLScript in the database, available on-premise and as the managed service SAP HANA Cloud.sap official, btpSAP's relational database platform, on-premise and in HANA Cloud
- cds-pgcds-pgA PostgreSQL adapter for SAP CDS, built by the SAP Mentors community, which gave CAP a Postgres persistence option years before @cap-js/postgres shipped.independent, capPostgreSQL adapter for SAP CDS from the SAP Mentors community
- cap-snowflakecap-snowflakeA CAP database adapter for Snowflake with OData V4 support, which the maintainer marks as early development, so its contract is expected to move.independent, capCAP database adapter for Snowflake with OData V4 support
- cds-mysqlcds-mysqlA MySQL and MariaDB database adapter for CAP that connects to a database instance and translates incoming CQL/CQN requests to it; the repository the package declares has been deleted.independent, capMySQL and MariaDB database adapter for CAP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
Flavors
“Welcome to the PostgreSQL database service for [SAP Cloud Application Programming Model](https://cap.cloud.sap) Node.js, based on streamlined database architecture and [*pg* driver](https://www.npmjs.com/package/pg) .” — cap-js/cds-dbs — postgres README
Contributors
History in the atlas
- The link named the root of a monorepo, so every crawl read the repository README — 'This is a monorepo for our SQL Database Services' — and filed it as this package's own: data/crawled/readmes/cap-js-postgres.md is that root README today, even though the flavor already cited the postgres subfolder. npm's record for @cap-js/postgres declares no repository directory, so the subfolder URL is the only place it can come from.
- The entry named no registry page, so the only address it offered was a repository it shares with three other packages.
- The repository's README states the relation: the four subfolders are parts of one monorepo, each published on its own.
- The PostgreSQL database service — the production option for running CAP off HANA, sharing the base service with the other three.
- First seen.
For your agent
- Ref
artifact:cap-js-postgres- JSON
- /artifacts/cap-js-postgres.json
- MCP
- Connecting an agent