Skip to Content
5 days ago

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

135 Views Last edit 5 days ago 3 rev


for a project that uses a sqlite3 db locally and a hana db in production. We are using 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:

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:

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;