Data Types
Choose correct types when modeling tables and declaring client variables, page variables, and action parameters.
Momen uses PostgreSQL underneath. What each type maps to in the database is collected in Database reference at the end.
Basic types
There are 12 basic types — the smallest usable units of the type system.
| Type | Format and limits |
|---|---|
| Text | Up to ~1 GB |
| BigInt | 8-byte integer, -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 |
| Decimal | Variable length, up to 131072 digits; exact decimal arithmetic, no float rounding error |
| Boolean | true / false |
| Timestamptz | YYYY-MM-DDTHH:mm:ss.sssZ; an absolute instant, rendered in the client’s local timezone |
| Date | YYYY-MM-DD; no time of day, unaffected by timezone |
| Timetz | HH:mm:ss.sssZ; a time of day only |
| Image | The file goes to object storage; the field holds a reference to the media record. .jpg, .jpeg, .png, .gif, .webp, .svg, .ico |
| Video | The file goes to object storage; the field holds a reference to the media record. .mp4, .mov, .webm |
| File | The file goes to object storage; the field holds a reference to the media record. any file type |
| Geo point | [longitude, latitude]; supports distance calculation and sorting by distance |
| JSON | Data of any type — a basic value, an object or an array; the shape does not have to be fixed |
JavaScript and many APIs use float doubles. DB Decimal is exact; mixing float math in custom code can introduce tiny errors before write-back.
Array
An array holds several values of one type and is shown as [element type] — [Text], [Object], [Order]. The element can be any type.
Object
An object is a structured type made up of properties.
- Properties — each has its own name, type and nullability. A property’s type can be a basic type, an array, an enum, a table type or another object, so objects nest to any depth.
- Versus JSON — JSON content is opaque to the type system and can only be read by path at runtime; every property of an object is a first-class member of the type system, directly referenceable by data binding and subject to type checking. Express known shapes as objects and leave JSON for the parts that genuinely are not fixed.
- Named objects — defined at project level, carry a name, and can be referenced anywhere in the project. Every named object can be viewed and edited under Object on the Data page.
- Private objects — produced in place by an API request body, response body and similar configuration. They have no name, their type reads Object, and they belong only to the location that produced them, so nothing else can reference them. A shape shared by several places has to be a named object.
Enum
An enum is a type whose values are restricted to a predefined set of enum values. It expresses a finite domain such as order status, review result or membership tier.
- Value names — identifiers: letters, digits and underscores only, never starting with a digit, and unique within the enum.
- Order — enum values are ordered, and that order carries to every place the enum is referenced.
- Storage — an enum column stores the enum value name, which makes those names part of the project’s contract with anything outside it.
Because live data stores the names, changing a value that is already in use rewrites existing rows:
- Deleting a value — after deployment, rows holding it are set to null; if the field is required, the deployment fails.
- Renaming a value — deployment migrates existing rows, but outside consumers of the string (custom code, external API callers) are not migrated.
Database reference
What each type becomes in PostgreSQL when used as a table field.
| Type | Type in the database |
|---|---|
| Text | TEXT |
| BigInt | BIGINT (the id primary key is BIGSERIAL) |
| Decimal | DECIMAL (that is, numeric) |
| Boolean | BOOLEAN |
| Timestamptz | TIMESTAMPTZ |
| Date | DATE |
| Timetz | TIMETZ |
| Image | bigint, column named <field>_id, foreign key to fz_stored_image |
| Video | bigint, column named <field>_id, foreign key to fz_stored_video |
| File | bigint, column named <field>_id, foreign key to fz_stored_file |
| Geo point | geography(Point, 4326) |
| JSON | JSONB |
| Enum | TEXT, holding the enum value name |
| Object | No column of its own |
| Array | No column of its own; one-to-many and many-to-many relations are backed by join tables |
Three consequences worth knowing:
- A media field stores a media record id; the file and its URL live in
fz_stored_imageand the like (not exposed to the outside), which is why a media record that is still referenced cannot be deleted in the database layer.It needs to be deleted in the resource manager. - An enum field stores the enum value name, which is why renaming or deleting a value rewrites existing rows.