Models and fields
Addon business models are Go structs that embed sdk.Model and declare fields with typed markers and optional sumeru struct tags.
Minimal model
package models
import "sumeru/core/sdk"
type MyNotes struct {
sdk.Model `sumeru:"model=my.notes"`
Name sdk.String `sumeru:"required,index,string=Name"`
Active sdk.Boolean `sumeru:"default=true"`
Body sdk.Text
}No ModelName(), Fields(), init(), or RegisterModel in model files. After adding a model struct, run make generate (part of make build) so zmodels.go registers it.
The Module for registration comes from manifest.json name.
Model inherit
Extend an existing model (same PostgreSQL table) from a dependent module with inherit=:
type PartnerContacts struct {
sdk.Model `sumeru:"inherit=core.partner"`
CustomerRank sdk.Integer `sumeru:"string=Customer Rank,default=0"`
}inherit=andmodel=are mutually exclusive on one struct.- The target model must already be registered (use
dependson the owning module). - Run
make generate, then-u your_modulefor additive schema sync. - Add view xpath inherit so new fields appear in forms.
See Model inherit how-to.
Field types
| Go type | SQL | Notes |
|---|---|---|
sdk.String | VARCHAR | Use size= tag for length |
sdk.Text | TEXT | |
sdk.Boolean | BOOLEAN | |
sdk.Integer | BIGINT | |
sdk.Float | REAL | 32-bit |
sdk.Float64 | DOUBLE PRECISION | 64-bit |
sdk.Numeric | NUMERIC | precision=, scale= |
sdk.Date / sdk.DateTime | DATE / TIMESTAMPTZ | |
sdk.Json | JSONB | |
sdk.Many2One[T] | BIGINT FK | comodel= when T is sdk.Any |
sdk.One2Many[T] / sdk.Many2Many[T] | virtual | comodel=, table=, left=, right= |
Cross-package FKs (wizards pointing at another module’s model) use sdk.Many2One[sdk.Any] plus comodel=other.model. Typed Many2One[T] only works when T is in the same Go package.
Selection lists: use sdk.String with selection=key:Label,key:Label in the tag.
Common tags
required, unique, index, default=, string= (label), column=, comodel=, selection=
Runtime API
Prefer sdk.Search, sdk.Create, sdk.Upsert with struct-based inputs. Records remain map[string]interface{} at runtime.