reflection

package
v0.0.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractColumnFromBunTag

func ExtractColumnFromBunTag(tag string) string

ExtractColumnFromBunTag extracts the column name from a bun tag Example: "id,pk" -> "id" Example: ",pk" -> "" (will fall back to json tag)

func ExtractColumnFromGormTag

func ExtractColumnFromGormTag(tag string) string

ExtractColumnFromGormTag extracts the column name from a gorm tag Example: "column:id;primaryKey" -> "id"

func GetModelColumns

func GetModelColumns(model any) []string

GetModelColumns extracts all column names from a model using reflection It checks bun tags first, then gorm tags, then json tags, and finally falls back to lowercase field names

func GetPrimaryKeyName

func GetPrimaryKeyName(model any) string

GetPrimaryKeyName extracts the primary key column name from a model It first checks if the model implements PrimaryKeyNameProvider (GetIDName method) Falls back to reflection to find bun:",pk" tag, then gorm:"primaryKey" tag

func Len added in v0.0.26

func Len(v any) int

Types

type ModelFieldDetail

type ModelFieldDetail struct {
	Name        string        `json:"name"`
	DataType    string        `json:"datatype"`
	SQLName     string        `json:"sqlname"`
	SQLDataType string        `json:"sqldatatype"`
	SQLKey      string        `json:"sqlkey"`
	Nullable    bool          `json:"nullable"`
	FieldValue  reflect.Value `json:"-"`
}

func GetModelColumnDetail

func GetModelColumnDetail(record reflect.Value) []ModelFieldDetail

GetModelColumnDetail - Get a list of columns in the SQL declaration of the model

type PrimaryKeyNameProvider added in v0.0.23

type PrimaryKeyNameProvider interface {
	GetIDName() string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL