Semantius Logo
DocsData CatalogEntities and Fields

Entities and Fields

On this page

An entity is a kind of record, such as a ticket or an order. Inserting a record into entities creates a database table, its REST API endpoint at /<table_name>, its access policies and its schema; deleting the record drops the table with every record in it. Each record in fields is a column of that table: inserting one adds the column, and deleting one drops the column with its values. A change to either is applied to the table in the same transaction, so the model and the database cannot drift apart.

Creating, changing and deleting entities and fields takes the admin permission.

Creating an entity

A new entity’s table starts with four columns, each with its row in fields:

ColumnWhat it holds
idThe record’s key, in the column named by id_column (default id). Its type depends on the entity’s id_type; see Keys.
labelThe record’s name, in the column named by label_column (default label), shown wherever the record is listed or linked. Required.
created_at, updated_atSet by the database. updated_at moves on every change.

The table also gets a full-text search_vector over its searchable fields (the label is searchable from the start), row-level security built from the entity’s permissions, and its endpoint, /<table_name>. The API picks up the change at once.

  • Every record needs a label. The label field is required, so an insert without one is refused (90258), unless a computed field writes it. Junction records need one too.
  • There is no created_by. Add a reference field to users with the default $user_id to record who created a record.

Entities

The entity record describes the table: its name and labels, its module and permissions, its key, and whether Semantius manages it.

Fields

The field record describes a column: its name and title, its format, whether it is required, its default, and what changing it does to the stored values.

Formats

A field’s format decides the column’s type, and with it what the database accepts.

Relationships

Relationships link records to each other through reference and parent fields: one to many, many to many and one to one. Subtypes and extensions share records with a base entity.

API

CallWhat it does
/entitiesThe entities, keyed by table_name, through create_entity, read_entity, update_entity and delete_entity.
/fieldsThe fields, keyed by id (tickets.status), through create_field, read_field, update_field and delete_field.
/<table_name>The entity’s records, through postgrestRequest.
/rpc/get_schemaThe schema of p_table_name: its entity row, its fields as properties with their inputMode, width, ctype and references, and its children. An unknown entity, and one whose schema the caller may not see (see The schema follows the permissions), both answer 404 with code 42P01.
/rpc/get_schemasThe schemas of p_table_names, a comma-separated list.
/rpc/get_schema_childrenThe child entities of p_table_name: the entities with a parent field to it.
/rpc/get_record_by_idOne record of p_entity_name by p_id, whatever its key type.
/rpc/fix_id_sequenceMoves the key counter of p_table above its highest id.

The schema’s required list is not the database’s: read each property’s inputMode to know whether a field is required.

Errors

CodeMeaning
90223A format change that would change the column type.
90236A record’s key cannot change.
90257, 90282clear on a required reference, or on a parent.
90258A required field holds no value.
90259A field cannot become required while records lack a value.
90260The entity is still referenced by a field of another entity.
90275The field is named by a rule.
90283, 90284A $user_id or relative-date default on a field that cannot take it.
23505A duplicate: a unique_value field, a field name, a table name or an id_prefix.
23514A value outside enum_values, or a name that breaks its pattern.
23503A reference to a record that does not exist.

The codes that business logic raises are listed under JsonLogic extensions.