-
Notifications
You must be signed in to change notification settings - Fork 150
Review databases "compiled to" from CAP Java #2329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
459586d
10986c8
2de4a7a
e5e563f
ec4b149
0cfc89d
8245fd0
c2117ce
ab723b4
7b77377
358eeb8
24c4808
41f6a44
e3eb935
fb3242f
51e7af9
ecd705e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,9 @@ Databases are deployed based on the entity definitions in your CDS models. This | |||||||||
|
|
||||||||||
| ## Using `cds compile`, ... | ||||||||||
|
|
||||||||||
| CDS compilation to database-specific DDLs is handled by the `cds compile` command, which is part of the [`cds` CLI](../../tools/cds-cli). When you run `cds deploy` or `cds watch`, this command is invoked automatically to generate the necessary DDL statements for your target database. | ||||||||||
| CDS compilation to database-specific DDLs is handled by the [`cds compile`](../../tools/cds-cli#cds-compile) command, which is part of the [`cds` CLI](../../tools/cds-cli). When you run `cds deploy` or `cds watch`, this command is invoked automatically to generate the necessary DDL statements for your target database. | ||||||||||
|
|
||||||||||
| In CAP Java, the DDL is generated by the Maven build which uses the [CDS Maven Plugin](../../java/developing-applications/building#cds-maven-plugin)'s [cds](../../java/assets/cds-maven-plugin-site/cds-mojo.html) goal to invoke `cds deploy --dry`. | ||||||||||
|
|
||||||||||
| You can also run the command manually to see the generated DDL for your models. For example, to inspect what the SQL DDL for your entire model would look like, simply run: | ||||||||||
|
|
||||||||||
|
|
@@ -81,6 +83,8 @@ cds env requires.db --profile production | |||||||||
| > [!tip] Dialects are inferred from profiles automatically | ||||||||||
| > You typically don't need to specify the `--dialect` option manually, as it is derived from your project configuration and the active profile. | ||||||||||
|
|
||||||||||
| > [!warning] Don't use `cds env` with CAP Java | ||||||||||
| CAP Java uses [Spring profiles](https://docs.spring.io/spring-boot/reference/features/profiles.html) at runtime, whereas CAP Node.js uses [`cds env` profiles](../../node.js/cds-env#profiles). | ||||||||||
|
|
||||||||||
|
|
||||||||||
| ### Using `cds deploy` | ||||||||||
|
|
@@ -181,13 +185,16 @@ CREATE TABLE sap_capire_bookshop_Books_Details ( ... ); | |||||||||
| ``` | ||||||||||
| ::: | ||||||||||
|
|
||||||||||
| > [!tip] Guaranteed & Stable Slugification | ||||||||||
| > The slugification effects are guaranteed and stable, which means that you can rely on it and use the slugified names in native SQL queries. For example, both of the following CQL queries are equivalent and will work as expected: | ||||||||||
| > [!tip] You may use slugified names in CAP Node.js | ||||||||||
| > In CAP Node.js, the slugification effects are guaranteed and stable, which means that you can rely on it and use the slugified names in _native SQL_ queries. For example, both of the following CQL queries are equivalent and will work as expected: | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or maybe one of these: ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or maybe one of these: slugged, slugify, sluiced, slugabed? |
||||||||||
| > | ||||||||||
| > ```js | ||||||||||
| > await cds.run `SELECT from sap.capire.bookshop.Books` | ||||||||||
| > await cds.run `SELECT from sap_capire_bookshop_Books` | ||||||||||
| > ``` | ||||||||||
|
|
||||||||||
| ```js | ||||||||||
| await cds.run `SELECT from sap.capire.bookshop.Books` | ||||||||||
| await cds.run `SELECT from sap_capire_bookshop_Books` | ||||||||||
| ``` | ||||||||||
| > [!warning] Don't use slugified names in CAP Java | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or maybe one of these: slugged, slugify, sluiced, slugabed? |
||||||||||
| In CAP Java, you can use fully qualified entity names with dots. The slugified names can't be used in CQL queries. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or maybe one of these: slugged, slugify, sluiced, slugabed? |
||||||||||
|
|
||||||||||
| > [!tip] | ||||||||||
| > Prefer entity names like `Books.Details` over _CamelCase_ variants like `BooksDetails`. While both work equally, they show up differently in native tools of databases that don't preserve case, for example in SAP HANA: The former will show up as `BOOKS_DETAILS`, while the latter shows up as `BOOKSDETAILS`, which is harder to read. | ||||||||||
|
|
@@ -276,14 +283,23 @@ CREATE TABLE Books ( | |||||||||
| ``` | ||||||||||
| ::: | ||||||||||
|
|
||||||||||
| > [!tip] Guaranteed & Stable Flattening | ||||||||||
| > The flattening effects are guaranteed and stable, which means that you can rely on it and use the flattened elements in native SQL queries. For example, both of the following CQL queries are equivalent and would work as expected: | ||||||||||
| The flattening effects for structured elements are guaranteed and stable. If a CDS model is compiled for usage with OData the only the flattened elements are preserved in the CDS model. | ||||||||||
|
agoerler marked this conversation as resolved.
Outdated
|
||||||||||
|
|
||||||||||
| ```js | ||||||||||
| await cds.run `SELECT price.amount from Books` | ||||||||||
| await cds.run `SELECT price_amount from Books` | ||||||||||
| ``` | ||||||||||
| > [!tip] Use flattening in runtime queries in CAP Node.js | ||||||||||
| > The flattening effects can also be used at runtime with CAP Node.js. For example, both of the following CQL queries are equivalent and would work as expected: | ||||||||||
| > | ||||||||||
| > ```js | ||||||||||
| > await cds.run `SELECT price.amount from Books` | ||||||||||
| > await cds.run `SELECT price_amount from Books` | ||||||||||
| > ``` | ||||||||||
|
|
||||||||||
| > [!warning] No flattening in runtime queries in CAP Java | ||||||||||
| > CAP Java does not perform an automatic flattening of path expressions: | ||||||||||
| > | ||||||||||
| > ```java | ||||||||||
| > Select.from("Books").columns("price_amount"); // valid | ||||||||||
| > Select.from("Books").columns("price.amount"); // invalid | ||||||||||
| > ``` | ||||||||||
|
|
||||||||||
| ### Associations ⇒ JOINs | ||||||||||
|
|
||||||||||
|
|
@@ -349,7 +365,7 @@ LEFT JOIN Genres as genre on genre_ID = genre.ID; -- [!code ++] | |||||||||
| > Looking closely at the above compiled SQL code, we can regard | ||||||||||
| > associations to be like _'Forward-declared' JOINs_, along these lines: | ||||||||||
| > | ||||||||||
| > 1. Association names `a.name` appear in queries as standard _table aliases_ | ||||||||||
| > 1. Association names `a.name` appear in queries as _table aliases_ | ||||||||||
| > 2. _JOINs_ are added automatically as per the following construction rule: | ||||||||||
| > | ||||||||||
| > _JOIN `a.target` as `a.name` on `a.on`_ | ||||||||||
|
|
@@ -467,13 +483,18 @@ However, even though CAP allows this, and handles all accesses correctly, it is | |||||||||
| > [!warning] DON'T use Database-Invalid Names! | ||||||||||
| > It's **strongly discouraged** to use names that contain non-ASCII characters, or conflict with database reserved words. Even more avoid [delimited names](../../cds/cdl#keywords-identifiers) in CDS models in the first place, as that impacts readability of your models. | ||||||||||
|
|
||||||||||
| > [!warning] Avoid using reserved Java keywords | ||||||||||
| > A CAP Java project usually uses generated [accessor interfaces](../../java/cds-data#generated-accessor-interfaces). Avoid using reserved Java keywords as identifiers in a CDS model as using Java keywords might cause generated interfaces that don't compile. You may use the `@cds.java.name` annotation to mitigate such conflicts. | ||||||||||
|
agoerler marked this conversation as resolved.
Outdated
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| ###### reserved-words | ||||||||||
| > [!important] Lists of Reserved Words | ||||||||||
| > Check out the reserved words for the databases you are targeting: \ | ||||||||||
| > [_SAP HANA_](https://help.sap.com/docs/HANA_CLOUD_DATABASE/c1d3f60099654ecfb3fe36ac93c121bb/28bcd6af3eb6437892719f7c27a8a285.html) | ||||||||||
| > , [_SQLite_](https://www.sqlite.org/lang_keywords.html) | ||||||||||
| > , [_H2_](https://www.h2database.com/html/advanced.html#keywords) | ||||||||||
| > , [_PostgreSQL_](https://www.postgresql.org/docs/current/sql-keywords-appendix.html) | ||||||||||
| > , [_Java_](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html) | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe one of these: slugged, slugify, sluiced, slugabed?