cds init my-bookshop
.@Sap/cds
package and wondering why the @Sap/generator-cds
package has a different name pattern (all the other packages are cds-...
). On this subject, Fred later makes what I think is a nice oblique reference to Conway's Law: "Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations".@Sap/generator-cds
, we can see that this provides a "binary" (executable) cds-gen
by looking at the output of npm info @Sap/generator
. This is used in turn by the cds
command.my-bookshop
project, and noting that the README.md
file contains a tutorial similar to what we're following here. We also briefly explore the @Sap
packages inside the node_modules
directory, especially the "binaries" in the .bin
directory such as cds
, cds-gen
, cdsc
, mime
and uuid
.cds init
based project generation, in particular the contents of the .vscode
directory, relating to the launch and debug facilities that VS Code offers.cat-service.cds
file in the srv
directory, and noticing immediately what the extension for CDS is doing for us (in terms of highlighting errors and even suggesting completions).using { Country, managed } from '@sap/cds/common';
common.cds
inside the @Sap/cds
package itself; the file provides some basic types and definitions that are common to many projects. Definitions for languages, currencies and countries are in this file, for example. We explore this common.cds
file here, looking at the managed
type and the concept of aspects.managed
aspect is used on the definition of the Orders
entity, and what that aspect brings to the entity in terms of extra fields that are automatically filled on certain events.sap.common
context, which is like a namespace, but within a file.cds compile
to see what is produced. In fact we don't even use the compile
command as that is the default, as we can see here:COMMANDS
c | compile ...individual models (= the default)
d | deploy ...data models to a database
s | serve ...service models to REST clients
b | build ...whole modules or projects
i | init ...jump-starts a new project
e | env get/set current cds configuration
r | repl cds's read-eval-event-loop
h | help shows usage for cds and individual commands
v | version prints detailed version information
cds srv/cat-service.cds
we get a whole load of output, which is in fact Core Schema Notation (CSN), specifically a plain JavaScript object representation thereof (there are different representations possible - see the cds.compile documentation for details).node_modules/.bin/
directory we see the cdsc
executable which is the CDS compiler, and what the cds
command uses for compilation. LET'S RUN IT! We see that it shows us all sorts of output in a help format, and we can explore what different types of compiler output are possible.cds compile
command, like this one which we run now: cds srv/cat-service.cds --to sql
which perhaps is more palatable to us right now:CREATE TABLE my_bookshop_Authors (
ID INTEGER,
name NVARCHAR(5000),
PRIMARY KEY(ID)
);
...
cds srv/cat-service.cds --to hana
which produces something like this:using MY_BOOKSHOP_BOOKS as MY_BOOKSHOP_BOOKS;
entity MY_BOOKSHOP_AUTHORS {
key ID : Integer;
NAME : String(5000);
BOOKS : association[*] to MY_BOOKSHOP_BOOKS on BOOKS.AUTHOR_ID = ID;
};
...
cds run
, which we do now, and we see a local server start up, listening by default on port 4004 (there's a story behind why the port is 4004 ... and it's not because of the first commercial the Intel microprocessor as I'd thought ... but I'll leave that for another time :-)). We can change this port by setting the value of the PORT
environmental variable too (e.g. PORT=1234 cds run
).CatalogService
to Banana
we can see what effect this has on how the service is served.cds run
and make sure we understand what's going on:[cds] - server listens at http://localhost:4004
[cds] - serving CatalogService at /catalog
[cds] - service definitions loaded from:
srv/cat-service.cds
node_modules/@sap/cds/common.cds
[cds] - launched in: 1350.885ms
srv/cat-service.cds
file but also the common.cds
file that we're using for the Country
and managed
definitions.cat-service.cds
:service Mexico {
entity Things {
key ID : Integer;
name : String;
}
}
cds run
we see:[cds] - serving CatalogService at /catalog
[cds] - serving Mexico at /mexico
.js
extension, i.e. cat-service.js
, in the same directory. By following this convention we can have the runtime use our JavaScript code to enhance the implementation of our definitions. This is Step 5 in the tutorial, by the way.srv.on ('READ', 'Books', ...)
in the cat-service.js
implementation by changing the body of the function from a single expression that is returning an array, to a block that executes a console.log
statement, and then returns the array.console.log
statement, which is a very small step towards a future investigation into logging and debugging (which we do in Episode 4). Hurray!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
36 | |
25 | |
17 | |
13 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 |