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 ¶
func AssignScanned ¶ added in v0.27.0
AssignScanned writes a value scanned from the DB (as an any holding the driver's concrete type, or nil for NULL) into the destination field. NULL coalesces to the field's Go zero value. Fields implementing sql.Scanner (sql.NullString, decimal/uuid types, ...) receive the raw value through their Scan method; everything else goes through ConvertAssign.
func ConvertAssign ¶ added in v0.27.0
ConvertAssign converts src (a driver value: int64, float64, bool, []byte, string or time.Time) into the pointer dest. It mirrors the subset of database/sql's convertAssign that the ORM relies on, with a reflection fallback for numeric/string kinds so non-default field types (int, uint, float32, named string types, ...) all work. Textual numbers and booleans ([]byte on MySQL's text protocol) are parsed.
func IndirectValue ¶
IndirectValue dereferences a Value through pointers.
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
// IsDeletedAt marks the soft-delete timestamp column.
IsDeletedAt 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
DeletedAt *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.
func (*Schema) InsertableColumns ¶
InsertableColumns returns columns to include on insert (skips relations, skip-marked, and zero-valued auto fields).
func (*Schema) SoftDeletes ¶
SoftDeletes reports whether the model carries a soft-delete timestamp column (a DeletedAt/deleted_at column, typically via embedding orm.SoftDeletes).