generator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFile

func GenerateFile(meta ModelMeta, outDir string) error

Types

type FieldMeta

type FieldMeta struct {
	FieldName    string
	Column       string
	Type         string
	IsPK         bool
	AutoIncr     bool
	IsJSON       bool     // Whether field is a JSON type
	JSONTypeName string   // Name of the JSON struct type (e.g. "UserMetadata")
	Doc          []string // Documentation comments
}

type GenConfig

type GenConfig struct {
	OutPath        string
	IncludeStructs []string
	ExcludeStructs []string
	FieldTypeMap   map[string]string
}

GenConfig holds parsed configuration from config.go

func ParseConfig

func ParseConfig(dir string) (*GenConfig, error)

ParseConfig parses config.go in the given directory for gen.Config

type JSONFieldMeta

type JSONFieldMeta struct {
	FieldName  string         // Name of the field in parent model (e.g. "Metadata")
	TypeName   string         // Name of the JSON struct type (e.g. "UserMetadata")
	ColumnName string         // Database column name
	Paths      []JSONPathMeta // List of paths in this JSON field
}

JSONFieldMeta holds information about a JSON field's path structure

type JSONPathMeta

type JSONPathMeta struct {
	GoName   string // Go field name (e.g. "Name")
	JSONPath string // JSON path (e.g. "$.name")
}

JSONPathMeta holds information about a single JSON path

type ModelMeta

type ModelMeta struct {
	PackageName       string
	ParentPackage     string // For generated code to reference parent package
	ModulePath        string // Module path like github.com/user/project
	PackagePath       string // Package path like models
	ModelName         string
	TableName         string
	Fields            []FieldMeta
	JSONFields        []JSONFieldMeta   // JSON field path definitions
	Doc               []string          // Documentation comments
	GeneratedAt       string            // Timestamp
	HasJSON           bool              // Whether imported encoding/json package is needed
	HasJSONField      bool              // Whether any field has type:json tag
	PKFieldName       string            // Cached PK Field Name
	PKColumnName      string            // Cached PK Column Name
	PKFieldType       string            // Cached PK Field Type
	IsAutoIncrementPK bool              // Cached PK AutoIncrement status
	SchemaStructName  string            // e.g. userSchema
	IsJSONOnly        bool              // True if struct is only used as JSON embed (no db tags/PK)
	HasDBTag          bool              // True if any field has a db tag
	TypeAliases       map[string]string // type A int → {"A": "int"}
	FieldTypeMap      map[string]string // User-defined type mappings from config
}

func ParseModels

func ParseModels(dir string) ([]ModelMeta, error)

func (ModelMeta) GetFieldType

func (m ModelMeta) GetFieldType(goType string) string

GetFieldType returns the appropriate field type based on Go type

func (ModelMeta) GoIsNonZero

func (m ModelMeta) GoIsNonZero(fieldName, goType string) string

GoIsNonZero returns the Go expression to check if a field is NOT zero value

func (ModelMeta) IsNumeric

func (m ModelMeta) IsNumeric(goType string) bool

IsNumeric checks if the Go type is numeric

func (ModelMeta) QualifyPKType

func (m ModelMeta) QualifyPKType() string

QualifyPKType returns the qualified type name for the PK field

Jump to

Keyboard shortcuts

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