on 2023 Mar 09 6:56 AM
Dear CAP Community,
I am trying to experiment with the cds repl using the famous bookshop demo example rolled out by SAP.
I have set up the Visual Studio code and installed all the necessary node modules like @sap/cds-dk along with installation of npm and nodejs. After launcing the cds repl using cds r and instantiating the cds facade object using -> const cds = require('@sap/cds').connect('db') in the repl, I am trying to call cds.entities, but I don't get the list of entities defined - Books, Authors, Orders. It is coming blank, do we know why?

Best Regards,
Tanmoy
Request clarification before answering.
You have to bootstrap your bookshop within your repl session:
❯ cds r
Welcome to cds repl v 7.5.0
> var server = cds.test() // ⬅️ Bootstrap works like this if you started repls within the booskhop dir
> [cds] - loaded model from 5 file(s):
srv/user-service.cds
srv/cat-service.cds
srv/admin-service.cds
db/schema.cds
../../../cds/common.cds
[cds] - connect to db > sqlite { url: ':memory:' }
> init from db/init.js
…
> { Genres } = cds.entities()
(ns) => !ns ? children : this.childrenOf (ns,filter)
> Genres.elements
{
name: string {
'@title': '{i18n>Name}',
localized: true,
type: 'cds.String',
length: 255,
'@Common.Label': '{i18n>Name}'
},
descr: string {
'@title': '{i18n>Description}',
localized: true,
type: 'cds.String',
length: 1000,
'@Common.Label': '{i18n>Description}'
},
ID: number { key: true, type: 'cds.Integer' },
parent: Association {
type: 'cds.Association',
target: 'sap.capire.bookshop.Genres',
keys: [ { ref: [ 'ID' ], '$generatedFieldName': 'parent_ID' } ]
},
parent_ID: number { type: 'cds.Integer', '@odata.foreignKey4': 'parent' },
children: Composition {
type: 'cds.Composition',
cardinality: { max: '*' },
target: 'sap.capire.bookshop.Genres',
on: [ { ref: [ 'children', 'parent' ] }, '=', { ref: [ '$self' ] } ]
},
texts: Composition {
type: 'cds.Composition',
cardinality: { max: '*' },
target: 'sap.capire.bookshop.Genres.texts',
on: [ { ref: [ 'texts', 'ID' ] }, '=', { ref: [ 'ID' ] } ]
},
localized: Association {
type: 'cds.Association',
target: 'sap.capire.bookshop.Genres.texts',
on: [
{ ref: [ 'localized', 'ID' ] },
'=',
{ ref: [ 'ID' ] },
'and',
{ ref: [ 'localized', 'locale' ] },
'=',
{ ref: [ '$user', 'locale' ] }
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As martin.stenzig3 pointed out you have to bootstrap your app.
One nice trick i use for bootstraping is using cds.test
const test = cds.test(‘./‘)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The way you are calling it, you don't have anything started in your cds environment. You can
1. Start a debugging session and place a breakpoint into an event handler to use the cds repl functionality in the debugger or
2. You can use the following commands (after you do 'cds r') to bootstrap the basic sql lite in memory db and load your model into it
cds.env.add ({ requires: { db: { kind:'sqlite', ...cds.env.requires.kinds.sqlite, credentials: cds.env.requires.db?.credentials?.url ? {url:':memory:'} : {database:':memory:'}}}})
cds.db = await cds.connect.to ('db')
const m = await cds.load('*',{}) .then (cds.minify)
await cds.deploy(m).to(cds.db,{})
for (let e of cds.db.entities) { console.log(e.kind,e.name)}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.