Database Mapper when column names are too long

I’m using a class inhereting OCP\AppFramework\Db\QBMapper to connect my items to the database. In my item class, I also have a jsonSerialize function to serialise the item e.g. for the API into json code.

Now is the problem, that some database columns are too long. But they have exectly the name, how I need to name the property within the API (specified by 3rd Party).

How can I solve this problem? Having shorter column name in the DB, but the long property name in the API?

e.g. in the schema the (too long) column is defined as

$table->addColumn('application_installation_enabled', 'boolean', [
   'default' => false,
   'notnull' => false,
]);

in the entity class I have the following code, resulting in the desired API json name ‘applicationInstallationEnabled’ in the Policy API endpoint:

class Policy extends Entity implements JsonSerializable {

    protected $accountCreationEnabled;

    public function jsonSerialize() {
      return [
        'applicationInstallationEnabled' => $this->applicationInstallationEnabled,
      }
}

Have you thought of defining custom column name mappings?

See: Database access — Nextcloud latest Developer Manual latest documentation

I think this might give you the freedom you need.

Christian

1 Like