Field types
Models embed sdk.Model and use typed field markers from sumeru/core/sdk. Schema is inferred at registration from Go types and sumeru struct tags. For declaration examples see Models & fields.
Scalar and relational types
| Go type | PostgreSQL | Notes |
|---|---|---|
sdk.String | VARCHAR (default 255) | size= for length; column= for physical name |
sdk.Text | TEXT | |
sdk.HTML | TEXT | Rich text; widget html |
sdk.Email | VARCHAR | Widget email |
sdk.Phone | VARCHAR | Widget phone |
sdk.URL | VARCHAR | Widget url |
sdk.UUID | VARCHAR(36) | Use default=uuid for server-generated values |
sdk.Boolean | BOOLEAN | |
sdk.Integer | BIGINT | min=, max= |
sdk.Float | REAL | 32-bit |
sdk.Float64 | DOUBLE PRECISION | 64-bit |
sdk.Numeric | NUMERIC(p,s) | precision=, scale= |
sdk.Money | NUMERIC(p,s) | Defaults 18,2; pair with currency=FieldName |
sdk.Date | DATE | |
sdk.Time | TEXT | Time-of-day string; widget time |
sdk.DateTime | TIMESTAMPTZ | |
sdk.Duration | NUMERIC(p,s) | Stored as decimal; widget duration |
sdk.Json | JSONB | |
sdk.Binary | TEXT | Attachment payload; widget binary |
sdk.Image | TEXT | Image payload; widget image |
sdk.Selection[T ~string] | VARCHAR(50) | Options from const blocks in selection_types.go |
sdk.Many2One[T] | BIGINT | FK; ondelete=; comodel= when using sdk.Any |
sdk.One2Many[T] | *(no column)* | inverse= names the Many2one on the child |
sdk.Many2Many[T] | *(no column)* | table=, left=, right= for join table |
sdk.Reference | VARCHAR | Polymorphic model name; widget reference |
sdk.Many2OneReference | BIGINT | Polymorphic id; model_field= names the model field |
Derived fields
Any scalar marker can carry:
related=other_field.subfield— read-only mirror of a related value (no separate column logic beyond the source).compute=name— filled by a handler registered withorm.RegisterCompute; optionalstorepersists to the column on write;readonlyblocks client edits.
Common struct tags
required, unique, index, default=, string= (label), column=, size=, precision=, scale=, currency=, min=, max=, comodel=, inverse=, ondelete=, table=, left=, right=, model_field=, related=, compute=, store, readonly, groups=
Typed selections do not use inline selection= tags — define const blocks and use sdk.Selection[YourType].
Registration
Generated models/zmodels.go calls sdk.MustRegister on make generate. Authors do not write Fields() or hand-register models in addon init(). Cross-module relation types come from generated models/zrefs.go after listing modules in depends.
See also
- Models & fields — declare every type with
engagement_cookbookexamples - Field attributes — view XML attributes
- SWC widget catalog — UI widgets per type