Documentation
¶
Overview ¶
Package reflectutil provides a thread-safe, allocation-amortized reflection cache. Models are parsed once on first use; subsequent accesses are O(1).
It is the single source of truth for: column name resolution, primary-key discovery, fillable/hidden lists, cast tags, and embedded base-model handling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Field ¶
type Field struct {
// Name is the Go struct field name (e.g. "CreatedAt").
Name string
// Column is the database column name (e.g. "created_at"), resolved from
// `column:"..."` tag or snake_case of Name.
Column string
// Index is the index path for reflect.Value.FieldByIndex.
Index []int
// Type is the field's Go type.
Type reflect.Type
// IsPrimary indicates the field is (part of) the primary key.
IsPrimary bool
// IsAutoIncrement marks an integer primary key as auto-increment.
IsAutoIncrement bool
// IsCreatedAt / IsUpdatedAt mark timestamp columns.
IsCreatedAt bool
IsUpdatedAt bool
// IsZeroOnInsert means "send NULL/skip when zero on insert".
IsZeroOnInsert bool
// Hidden columns are never serialized via ToMap.
Hidden bool
// Fillable indicates the column accepts mass assignment.
Fillable bool
// Cast is the registered cast name (e.g. "json", "date", "bool").
Cast string
// HasDefault is true when the column has a struct-tag default.
HasDefault bool
// Default is the literal default value as written in the tag.
Default string
// Nullable as declared on the field tag.
Nullable bool
// Skip means: ignore this field for persistence (`column:"-"`).
Skip bool
// IsRelation marks the field as a relation (slice of struct / pointer to
// struct) discovered automatically; relations are not persisted as columns.
IsRelation bool
}
Field describes one persistent struct field.
type Schema ¶
type Schema struct {
Type reflect.Type
Table string
Fields []*Field
PrimaryKey *Field
CreatedAt *Field
UpdatedAt *Field
// contains filtered or unexported fields
}
Schema describes a parsed model type.
func Parse ¶
Parse returns the cached Schema for v's underlying struct type. It transparently dereferences pointers and slices.
func (*Schema) FieldByColumn ¶
FieldByColumn returns the Field with matching column name, or nil.
func (*Schema) FieldByName ¶
FieldByName returns the Field with matching Go name, or nil.
Click to show internal directories.
Click to hide internal directories.