Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions guides/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,12 @@ Instead, they protect the integrity of your data in the database layer against p

## Standard Database Functions

A specified set of standard functions - inspired by [OData](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_StringandCollectionFunctions) and [SAP HANA](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/alphabetical-list-of-functions?locale=en-US) - is supported in a **database-agnostic**, hence portable way, and translated to the best-possible native SQL functions or polyfills during runtime (currently only Node.js) and for your CDL files.
A specified set of standard functions - inspired by [OData](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_StringandCollectionFunctions) and [SAP HANA](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/alphabetical-list-of-functions?locale=en-US) - is supported in a **database-agnostic**, hence portable way. The functions are translated to the best-possible database-specific SQL expressions at runtime and also during compilation of your CDL files.


### OData standard functions

The `@sap/cds-compiler` and all CAP Node.js database services come with out of the box support for common OData functions.
The `@sap/cds-compiler` and the database services come with out of the box support for common OData functions.

::: warning Case Sensitivity
The OData function mappings are case-sensitive and must be written as in the list below.
Expand Down Expand Up @@ -1021,6 +1021,8 @@ For example, `startsWith` instead of `startswith` will be passed as-is to the da
If you provide more than one argument, the `round` function may behave differently depending on the database.
:::

<div class="impl node">

#### Date and Time Functions

- `year(x)`, `month(x)`, `day(x)`, `hour(x)`, `minute(x)`, `second(x)`
Expand All @@ -1038,11 +1040,14 @@ For example, `startsWith` instead of `startswith` will be passed as-is to the da
- `mindatetime()`
Returns the earliest possible point in time: `'0001-01-01T00:00:00.000Z'`.

</div>

#### Aggregate Functions

- `min(x)`, `max(x)`, `sum(x)`, `average(x)`, `count(x)`, `countdistinct(x)`
Standard aggregate functions used to calculate minimum, maximum, sum, average, count, and distinct count of values.

<div class="impl node">

### SAP HANA Functions

Expand All @@ -1066,7 +1071,7 @@ For the SAP HANA functions, both usages are allowed: all-lowercase as given abov

### Special Runtime Functions

In addition to the OData and SAP HANA standard functions, the **CAP runtimes** provides special functions that are only available for runtime queries:
In addition to the OData and SAP HANA standard functions, the **CAP runtime** provides special functions that are only available for runtime queries:

- `search(x, y)`
Checks whether `y` is contained in any element of `x` (fuzzy matching may apply).
Expand All @@ -1079,6 +1084,8 @@ In addition to the OData and SAP HANA standard functions, the **CAP runtimes** p
- `now()`
Returns the current timestamp.

</div>

## Using Native Features { #native-db-functions}

In general, the CDS 2 SQL compiler doesn't 'understand' SQL functions but translates them to SQL generically as long as they follow the standard call syntax of `function(param1, param2)`. This allows you to use native database functions inside your CDS models.
Expand Down Expand Up @@ -1191,4 +1198,4 @@ Once you have 2 non-HANA local databases, you need to have 2 distinct database c

</div>

CAP samples demonstrate this in [@capire/bookstore](https://github.com/capire/bookstore/tree/main/db).
CAP samples demonstrate this in [@capire/bookstore](https://github.com/capire/bookstore/tree/main/db).