Documentation
¶
Index ¶
- func GeneratePrefix(tableName string) string
- func PascalCaseToSnakeCase(s string) string
- func Pluralize(s string) string
- func Singularize(s string) string
- func SnakeCaseToCamelCase(s string) string
- func SnakeCaseToPascalCase(s string) string
- type FieldData
- type MethodConfig
- type ModelData
- type TemplateData
- type Templates
- type TypeMapper
- func (tm *TypeMapper) BuildGormTag(column *models.Column, table *models.Table) string
- func (tm *TypeMapper) BuildRelationshipTag(constraint *models.Constraint, isParent bool) string
- func (tm *TypeMapper) GetSQLTypesImport() string
- func (tm *TypeMapper) NeedsFmtImport(generateGetIDStr bool) bool
- func (tm *TypeMapper) NeedsTimeImport(goType string) bool
- func (tm *TypeMapper) SQLTypeToGoType(sqlType string, notNull bool) string
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeneratePrefix ¶
GeneratePrefix generates a 3-letter prefix from a table name Examples: process → PRO, mastertask → MTL, user → USR
func PascalCaseToSnakeCase ¶
PascalCaseToSnakeCase converts PascalCase to snake_case Examples: UserID → user_id, HTTPRequest → http_request
func Pluralize ¶
Pluralize converts a singular word to plural Basic implementation with common rules
func Singularize ¶
Singularize converts a plural word to singular Basic implementation with common rules
func SnakeCaseToCamelCase ¶
SnakeCaseToCamelCase converts snake_case to camelCase Examples: user_id → userID, http_request → httpRequest
func SnakeCaseToPascalCase ¶
SnakeCaseToPascalCase converts snake_case to PascalCase Examples: user_id → UserID, http_request → HTTPRequest
Types ¶
type FieldData ¶
type FieldData struct {
Name string // Go field name (PascalCase)
Type string // Go type
GormTag string // Complete gorm tag
JSONTag string // JSON tag
Comment string // Field comment
}
FieldData represents a single field in a struct
type MethodConfig ¶
type MethodConfig struct {
GenerateTableName bool
GenerateSchemaName bool
GenerateTableNameOnly bool
GenerateGetID bool
GenerateGetIDStr bool
GenerateSetID bool
GenerateUpdateID bool
GenerateGetIDName bool
GenerateGetPrefix bool
}
MethodConfig controls which helper methods to generate
func DefaultMethodConfig ¶
func DefaultMethodConfig() *MethodConfig
DefaultMethodConfig returns a MethodConfig with all methods enabled
func LoadMethodConfigFromMetadata ¶
func LoadMethodConfigFromMetadata(metadata map[string]interface{}) *MethodConfig
LoadMethodConfigFromMetadata loads method configuration from metadata map
type ModelData ¶
type ModelData struct {
Name string
TableName string // schema.table format
SchemaName string
TableNameOnly string // just table name without schema
Comment string
Fields []*FieldData
Config *MethodConfig
PrimaryKeyField string // Name of the primary key field
PrimaryKeyType string // Go type of the primary key field
IDColumnName string // Name of the ID column in database
Prefix string // 3-letter prefix
}
ModelData represents a single model/struct in the template
func NewModelData ¶
func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper) *ModelData
NewModelData creates a new ModelData from a models.Table
func (*ModelData) AddRelationshipField ¶
AddRelationshipField adds a relationship field to the model
type TemplateData ¶
type TemplateData struct {
PackageName string
Imports []string
Models []*ModelData
Config *MethodConfig
}
TemplateData represents the data passed to the template for code generation
func NewTemplateData ¶
func NewTemplateData(packageName string, config *MethodConfig) *TemplateData
NewTemplateData creates a new TemplateData with the given package name and config
func (*TemplateData) AddImport ¶
func (td *TemplateData) AddImport(importPath string)
AddImport adds an import to the template data (deduplicates automatically)
func (*TemplateData) AddModel ¶
func (td *TemplateData) AddModel(model *ModelData)
AddModel adds a model to the template data
func (*TemplateData) FinalizeImports ¶
func (td *TemplateData) FinalizeImports()
FinalizeImports sorts and organizes imports
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates holds the parsed templates
func NewTemplates ¶
NewTemplates creates and parses the templates
func (*Templates) GenerateCode ¶
func (t *Templates) GenerateCode(data *TemplateData) (string, error)
GenerateCode executes the template with the given data
type TypeMapper ¶
type TypeMapper struct {
// contains filtered or unexported fields
}
TypeMapper handles type conversions between SQL and Go types
func NewTypeMapper ¶
func NewTypeMapper() *TypeMapper
NewTypeMapper creates a new TypeMapper with default settings
func (*TypeMapper) BuildGormTag ¶
BuildGormTag generates a complete GORM tag string for a column
func (*TypeMapper) BuildRelationshipTag ¶
func (tm *TypeMapper) BuildRelationshipTag(constraint *models.Constraint, isParent bool) string
BuildRelationshipTag generates GORM tag for relationship fields
func (*TypeMapper) GetSQLTypesImport ¶
func (tm *TypeMapper) GetSQLTypesImport() string
GetSQLTypesImport returns the import path for sql_types
func (*TypeMapper) NeedsFmtImport ¶
func (tm *TypeMapper) NeedsFmtImport(generateGetIDStr bool) bool
NeedsFmtImport checks if we need fmt import (for GetIDStr method)
func (*TypeMapper) NeedsTimeImport ¶
func (tm *TypeMapper) NeedsTimeImport(goType string) bool
NeedsTimeImport checks if the Go type requires time package import
func (*TypeMapper) SQLTypeToGoType ¶
func (tm *TypeMapper) SQLTypeToGoType(sqlType string, notNull bool) string
SQLTypeToGoType converts a SQL type to its Go equivalent Handles nullable types using ResolveSpec sql_types package
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements the writers.Writer interface for GORM models
func NewWriter ¶
func NewWriter(options *writers.WriterOptions) *Writer
NewWriter creates a new GORM writer with the given options
func (*Writer) WriteDatabase ¶
WriteDatabase writes a complete database as GORM models
func (*Writer) WriteSchema ¶
WriteSchema writes a schema as GORM models