Documentation
¶
Overview ¶
Package r3tag provides struct tag parsing for r3 entities.
It handles the `r3` tag (primary) with `db` tag as fallback for column mapping, and finally the `gorm` tag (column:/primaryKey) so gorm-tagged models resolve to the same physical columns the GORM driver binds.
Column tag syntax (r3 or db):
r3:"column_name" r3:"column_name,pk" r3:"column_name,pk,soft_delete" r3:"-" // skip this field r3:"soft_delete" // column name derived from field name db:"column_name,pk" // fallback when no r3 tag gorm:"column:name" // fallback when neither r3 nor db names the column
Relation tag syntax (r3 only):
r3:"rel:has-many,fk:city_id" r3:"rel:belongs-to,fk:city_id" r3:"rel:has-many,fk:city_id,table:translations"
Capability flags (additive — they tighten the permissive defaults, never widen):
r3:"secret_token,no-filter,no-sort,no-output" // hidden from filter/sort/select r3:"population,readonly" // not creatable, not mutable r3:"slug,immutable" // creatable once, not mutable r3:"status,enum:draft|planned|published" // enum type + allowed values
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnTag ¶
type ColumnTag struct {
Column string // resolved column name
IsPK bool // field is the primary key
Skip bool // field should be skipped (tag value is "-")
SoftDelete bool // r3:"soft_delete"
// Capability flags. They are additive and only ever tighten the schema's
// permissive defaults (see r3.SchemaOf) — never widen them.
NoFilter bool // r3:"...,no-filter" — not allowed in Query.Filters
NoSort bool // r3:"...,no-sort" — not allowed in Query.Sorts
NoOutput bool // r3:"...,no-output" — hidden from SELECT and serialized output
ReadOnly bool // r3:"...,readonly" — not creatable and not mutable
Immutable bool // r3:"...,immutable" — creatable once, then not mutable
Enum []string // r3:"...,enum:a|b|c" — enum data type with the allowed values
Codec string // r3:"...,codec:name" — value codec name (resolved in schema derivation)
}
ColumnTag holds parsed column-level tag info for a single struct field.
func ParseColumnTag ¶
func ParseColumnTag(field reflect.StructField) ColumnTag
ParseColumnTag reads column metadata from struct tags. Priority: `r3` tag first, `db` tag as fallback, then the `gorm` tag's column/primaryKey info so gorm-tagged models derive the same physical columns the GORM driver binds. If no tag provides a column name, snake_case of the field name is used.
type RelationKind ¶
type RelationKind int
RelationKind describes the type of relationship between two entities.
const ( // RelHasMany represents a one-to-many relationship. RelHasMany RelationKind = iota // RelBelongsTo represents a many-to-one relationship. RelBelongsTo // RelManyToMany represents a many-to-many relationship via a join table. RelManyToMany )
type RelationTag ¶
type RelationTag struct {
Kind RelationKind
FKColumn string // foreign key column name (or left FK for M2M)
RefColumn string // right FK column for M2M join table
TableName string // explicit table name override (optional)
JoinTable string // join table name for M2M relations
Owned bool // if true, children are lifecycle-bound to parent (delete orphans on update)
}
RelationTag holds parsed relation tag info.
func ParseRelationTag ¶
func ParseRelationTag(field reflect.StructField) (RelationTag, bool)
ParseRelationTag parses the `r3` struct tag on a relation field. Returns a RelationTag and true if the tag declares a valid relation.