Documentation
¶
Index ¶
- func DefaultAbbreviations() map[string]string
- func GetElemType(valueOf reflect.Value) reflect.Type
- func GetElemValue(valueOf reflect.Value) reflect.Value
- func GetFieldNames(typeOf reflect.Type) (names []string)
- func GetTableID(typeOf reflect.Type) (reflect.StructField, bool)
- func GetTableModel(fieldOf reflect.Value) reflect.Value
- func GetTagValue(tag string, key string) (string, bool)
- func HasTagValue(tag string, key string) bool
- func IsTableModel(fieldOf reflect.Value) bool
- func LoadAbbreviationsFromData(data []byte) error
- func LoadAbbreviationsFromFile(path string) error
- func ParseSchemaTag(tag string) (schema, prefix string)
- func ParseTableNameByType(typeOf reflect.Type) string
- func ParseTableNameByValue(valueOf reflect.Value) string
- func RegisterAbbreviations(abbrs map[string]string)
- func TableNameMethod(valueOf reflect.Value) string
- func TableNamePattern(name string) string
- func ToAnySlice(value any) ([]any, int)
- func ToCamelCase(s string) string
- func ToPlural(name string) string
- func ToSingular(name string) string
- func ToSnakeCase(word string) string
- func ToTitleCase(word string) string
- type Imports
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAbbreviations ¶ added in v0.9.4
DefaultAbbreviations returns the default set of common abbreviations.
func GetElemType ¶
GetElemType returns the element type of a pointer If the value is a pointer, it returns the element type Otherwise, it returns the type itself
func GetElemValue ¶
GetElemValue returns the element value of a pointer If the value is a non-nil pointer, it returns the element Otherwise, it returns the value itself
func GetFieldNames ¶
GetFieldNames returns a slice of field names for the given struct type. It only includes exported fields.
func GetTableID ¶
func GetTableID(typeOf reflect.Type) (reflect.StructField, bool)
GetTableID returns the struct field with the name "ID" in the given table model type. If no such field exists, it returns an empty StructField and false.
func GetTableModel ¶
GetTableModel returns the "Model" field of the given table model field. If the field is not a table model, or if the "Model" field does not exist, it returns an invalid reflect.Value.
func GetTagValue ¶
GetTagValue gets tag value by key It returns the value and a boolean indicating if the key was found Supports both semicolon and comma as separators, and both "key:value" and "key=value" formats
func HasTagValue ¶
HasTagValue checks if tag has key value It returns true if the tag contains the specified key Supports both semicolon and comma as separators
func IsTableModel ¶
IsTableModel checks if the given field is a table model. A table model is a struct type that has a field named "Model" of type *T.
func LoadAbbreviationsFromData ¶ added in v0.9.8
LoadAbbreviationsFromData loads custom abbreviations from JSON bytes. The data should contain a JSON object mapping Go abbreviation names to their snake_case forms, e.g. {"ETag": "etag", "CRM": "crm"}.
func LoadAbbreviationsFromFile ¶ added in v0.9.8
LoadAbbreviationsFromFile loads custom abbreviations from a JSON file. The file should contain a JSON object mapping Go abbreviation names to their snake_case forms, e.g. {"ETag": "etag", "CRM": "crm"}. If the file does not exist, no error is returned.
func ParseSchemaTag ¶
ParseSchemaTag parses the schema tag and returns the schema name and table prefix. Example: "public;prefix:t_" returns ("public", "t_") Example: "auth" returns ("auth", "")
func ParseTableNameByType ¶
ParseTableNameByType parses table name by type It uses the TableName method if available, otherwise uses the type name
func ParseTableNameByValue ¶
ParseTableNameByValue parses table name by value If method TableName is found, return its value Otherwise, parse table name by type name
func RegisterAbbreviations ¶ added in v0.9.4
RegisterAbbreviations adds custom abbreviations for ToSnakeCase. Abbreviations are merged with the defaults; custom ones override defaults. For example, RegisterAbbreviations(map[string]string{"CRM": "crm"}) makes "CRMSystem" convert to "crm_system".
func TableNameMethod ¶
TableNameMethod tries to get table name from method TableName If method TableName is not found, return empty string
func TableNamePattern ¶
TableNamePattern is the default name patterning for mapping struct to table It converts the name to snake_case format
func ToAnySlice ¶ added in v0.8.6
ToAnySlice converts a value to a slice of any type.
func ToCamelCase ¶ added in v0.8.6
ToCamelCase converts snake_case to CamelCase
func ToSingular ¶ added in v0.8.6
ToSingular converts a plural name to its singular form.
func ToSnakeCase ¶
ToSnakeCase converts camelCase or PascalCase to snake_case. Registered abbreviations are kept together (e.g. "PRs" -> "prs" not "p_rs").
func ToTitleCase ¶ added in v0.8.6
ToTitleCase converts a string to title case It capitalizes the first letter of each word
Types ¶
type Imports ¶ added in v0.8.6
type Imports struct {
// contains filtered or unexported fields
}
func NewImports ¶ added in v0.8.6
func NewImports() *Imports