Skip to Content
0
5 days ago

CAP - @sql.append for different sql dialects - Sequence

135 Views Last edit 5 days ago 3 rev

Hi,

for a project that uses a sqlite3 db locally and a hana db in production. We are using https://cap.cloud.sap to create the database table.

I would like to create display an external facing ID for the end-users that is easier to read then a UUID. It would be easy to create such a "displayId" as an Integer and use AUTOINCREMENT for sqlite or and "IDENTITY column" in hana as described here: https://blogs.sap.com/2014/06/04/quick-note-on-identity-column-in-sap-hana/

But as far as I know CAP doesn't support the AUTOINCREMENT keyword.

I found this blogpost which does more or less what I need but the solution feels a bit complicated:

https://cap.cloud.sap/docs/guides/databases?q=%40sql.append#mapping-cds-to-sql

Is it possible to use the @sql.append and change the string that is appended to the table according to the current database dialect?

For example:

if(db.type === 'hana'){
  define type Autoincrement: Integer @sql.append : 'GENERATED BY DEFAULT AS IDENTITY';
} else {
  define type Autoincrement: Integer @sql.append : 'AUTOINCREMENT';
}
entity User: {
  cuiddisplayId : Autoincrement;
  description : String;
  name : String;
}