cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CAP - CDS Repl

ravenclaw
Participant
1,940

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

Accepted Solutions (0)

Answers (3)

Answers (3)

patricebender
Product and Topic Expert
Product and Topic Expert
0 Likes

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' ] }
    ]
  }
}
Aydin-Ozcan
Explorer
0 Likes

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(‘./‘)

martinstenzig
Contributor
0 Likes

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)}