Documentation
¶
Index ¶
- func ExtractColumnFromBunTag(tag string) string
- func ExtractColumnFromGormTag(tag string) string
- func GetModelColumns(model any) []string
- func GetPrimaryKeyName(model any) string
- func GetPrimaryKeyValue(model any) any
- func GetSQLModelColumns(model any) []string
- func IsColumnWritable(model any, columnName string) bool
- func Len(v any) int
- type ModelFieldDetail
- type PrimaryKeyNameProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractColumnFromBunTag ¶
ExtractColumnFromBunTag extracts the column name from a bun tag Example: "id,pk" -> "id" Example: ",pk" -> "" (will fall back to json tag)
func ExtractColumnFromGormTag ¶
ExtractColumnFromGormTag extracts the column name from a gorm tag Example: "column:id;primaryKey" -> "id"
func GetModelColumns ¶
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 This function recursively processes embedded structs to include their fields
func GetPrimaryKeyName ¶
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 GetPrimaryKeyValue ¶ added in v0.0.31
GetPrimaryKeyValue extracts the primary key value from a model instance Returns the value of the primary key field
func GetSQLModelColumns ¶ added in v0.0.52
GetSQLModelColumns extracts column names that have valid SQL field mappings This function only returns columns that: 1. Have bun or gorm tags (not just json tags) 2. Are not relations (no rel:, join:, foreignKey, references, many2many tags) 3. Are not scan-only embedded fields
func IsColumnWritable ¶ added in v0.0.32
IsColumnWritable checks if a column can be written to in the database For bun: returns false if the field has "scanonly" tag For gorm: returns false if the field has "<-:false" or "->" (read-only) tag This function recursively searches embedded structs
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 This function recursively processes embedded structs to include their fields
type PrimaryKeyNameProvider ¶ added in v0.0.23
type PrimaryKeyNameProvider interface {
GetIDName() string
}