Comments (6)
Hi @pwasem,
change your .cdsrc.json to add the dialect to the postgres section:
{
"features": {
"fiori_preview": true
},
"requires": {
"db": {
"kind": "postgres"
},
"postgres": {
"dialect": "plain", // << Add the dialect
"impl": "cds-pg",
"model": [
"app"
]
}
}
}
And change your default-env.json to the tags "plain" and "db":
{
"PORT": 5005,
"VCAP_SERVICES": {
"postgres": [
{
"name": "postgres",
"label": "postgres",
"tags": ["plain", "db"], // << Change the tags here
"credentials": {
"host": "postgres-svc",
"port": "5432",
"user": "slonik",
"password": "topsekret",
"database": "cap-ratings",
"schema": "public"
}
}
]
},
"DEBUG": "ratings-service"
}
That should do the trick.
Cheers,
Sebastian
from cds-pg.
Addition:
I was in doubt if this could be a connection issue, but
- host
postgres-svc
is reachable:
node ➜ /workspaces/cap-ratings $ ping postgres-svc
PING postgres-svc (172.18.0.2) 56(84) bytes of data.
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=1 ttl=64 time=0.080 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=2 ttl=64 time=0.089 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=3 ttl=64 time=0.089 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=4 ttl=64 time=0.122 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=5 ttl=64 time=0.128 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=6 ttl=64 time=0.164 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=7 ttl=64 time=0.091 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=8 ttl=64 time=0.170 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=9 ttl=64 time=0.191 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=10 ttl=64 time=0.189 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=11 ttl=64 time=0.250 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=12 ttl=64 time=0.259 ms
^C
--- postgres-svc ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11223ms
rtt min/avg/max/mdev = 0.080/0.151/0.259/0.059 ms
node ➜ /workspaces/cap-ratings $ npm run deploy
> [email protected] deploy
> npx cds-pg deploy app --to postgres
[cds.connect] - No service definition found for 'postgres', as required by 'cds.requires.postgres': {
impl: 'cds-pg',
model: [ 'app' ],
credentials: {
host: 'postgres-svc',
port: '5432',
user: 'slonik',
password: 'topsekret',
database: 'cap-ratings',
schema: 'public'
}
}
(node:2384) UnhandledPromiseRejectionWarning: Error: No service definition found for 'postgres'
at AsyncFunction.connect.to (/workspaces/cap-ratings/node_modules/@sap/cds/lib/connect/index.js:42:11)
at async Object.to (/workspaces/cap-ratings/node_modules/@sap/cds/lib/deploy.js:21:23)
at async deploy (/workspaces/cap-ratings/node_modules/cds-pg/bin/cds-pg.js:11:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2384) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2384) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
node ➜ /workspaces/cap-ratings $
- and postgres 14 is also up and running:
const { Pool } = require('pg')
const testConnection = async () => {
const pool = new Pool({
connectionString: 'postgres://slonik:topsekret@postgres-svc:5432/cap-ratings'
})
const { rows: [result] } = await pool.query('SELECT 1 as one')
console.log(result)
await pool.end()
}
testConnection()
node ➜ /workspaces/cap-ratings $ node test-connection.js
{ one: 1 }
So it looks like an issue related to cds
.
from cds-pg.
Hi @pwasem ,
@vobu, @sjvans and I updated cds-pg today to make it compatible with @sap/cds 5.5. I've tested the change in my pg-beershop project. Please check my adjustments to default-env.json and package.json#L82. Right now this is quite a hack as without this configuration no connection to the db is established. and the dialect "plain" must be passed to the _dialect variable in @sap/cds/libx/_runtime/common/utils/quotingStyles.js.
CU
Gregor
from cds-pg.
Hi @pwasem,
The problem is in your default-env.json and in your deployment command.
In your default-env.json make sure to have the tags plain
and/or db
and in your deploy command you need to follow the example in the cds-pg README: npx cds-pg deploy srv --to db
.
CAP merges the requires sections "db" and "postgres" in your package.json
and actually forgets the "postgres" service and looks for the "db" service. That's why the deploy command has --to db
as a parameter. The "kind" information is also stripped during merging of the configuration values and only the "dialect" is left.
CAP then checks if there is a VCAP service whose name matches the service name (db
), whose tag matches the context + ':' + service name
(cds:db
), whose tag match the dialect or kind (plain
and undefined
) or whose label matches the dialect or kind. See @sap/cds/lib/env/index.js - function _add_vcap_services_to
.
Kind regards,
Sebastian
from cds-pg.
hi @pwasem @gregorwolf @sebastianesch
regarding the original error, please see https://cap.cloud.sap/docs/advanced/troubleshooting#why-does-the-server-crash-with-no-service-definition-found-for-srv-name
deploy to db bypasses this, because the service name lookup isn’t done for the well-known requires property „db“.
best,
sebastian
from cds-pg.
Hi @pwasem,
The problem is in your default-env.json and in your deployment command.
In your default-env.json make sure to have the tags
plain
and/ordb
and in your deploy command you need to follow the example in the cds-pg README:npx cds-pg deploy srv --to db
.CAP merges the requires sections "db" and "postgres" in your
package.json
and actually forgets the "postgres" service and looks for the "db" service. That's why the deploy command has--to db
as a parameter. The "kind" information is also stripped during merging of the configuration values and only the "dialect" is left.CAP then checks if there is a VCAP service whose name matches the service name (
db
), whose tag matches thecontext + ':' + service name
(cds:db
), whose tag match the dialect or kind (plain
andundefined
) or whose label matches the dialect or kind. See @sap/cds/lib/env/index.js - function_add_vcap_services_to
.Kind regards, Sebastian
How should the actual default-env.json
look in this case?
Thx!
from cds-pg.
Related Issues (20)
- Invalid SQL query when Draft Entity make reference to other Draft Entity in OData call. HOT 3
- Vulnerability in momentjs 2.9.1 HOT 3
- Error upon modifying view in service HOT 1
- Strong security issue regarding indirect dependency to jsonwebtoken npm-module 8.x
- PATCH is executed on active entity for drafts with compositions HOT 3
- Error: [cds-dbm] - failed to load model undefined (STDERR, APP/TASK/deploy-to-postgresql)# HOT 2
- TypeError: Cannot read properties of undefined (reading 'definitions') HOT 4
- connection closed after each query
- Date conversion interprets timezone incorrectly
- Get request on entity not working
- Retain Column Name as case sensitive during deployment
- Wrong type cast of boolean HOT 1
- Query draft entities on db layer
- broken connectivity in 0.1.36 when using "cds watch" instead of "cds serve". using cap cds 6.6
- error: relation "[tablename]" does not exist
- duplicate key entry HOT 2
- cds-pg deploy fails with "Cannot find module '@sap/cds/lib/deploy'"
- Initial Release schedule?
- ERROR: syntax error at or near "LOCK" at character - STATEMENT: SELECT 1 FROM My_Type ALIAS_1 WHERE ( code = 1 ) LIMIT 1 FOR SHARE LOCK
- Query values must be an array ERROR
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cds-pg.