orm_generator

package
v0.0.50 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLICommands

type CLICommands struct {
}

CLICommands provides ORM generation CLI commands

func NewCLICommands

func NewCLICommands() *CLICommands

func (*CLICommands) GetRootCommand

func (cli *CLICommands) GetRootCommand() *cobra.Command

type CodeGenerator

type CodeGenerator struct {
	// contains filtered or unexported fields
}

CodeGenerator handles generation of type-safe ORM code

func NewCodeGenerator

func NewCodeGenerator(config GenerationConfig) *CodeGenerator

func (*CodeGenerator) CleanOutput

func (g *CodeGenerator) CleanOutput() error

func (*CodeGenerator) DiscoverModels

func (g *CodeGenerator) DiscoverModels(packagePath string) error

func (*CodeGenerator) GenerateAll

func (g *CodeGenerator) GenerateAll() error

func (*CodeGenerator) GenerateForModel

func (g *CodeGenerator) GenerateForModel(modelName string) error

func (*CodeGenerator) GetModel

func (g *CodeGenerator) GetModel(name string) (*ModelMetadata, bool)

func (*CodeGenerator) GetModelNames

func (g *CodeGenerator) GetModelNames() []string

func (*CodeGenerator) GetModelsByTable

func (g *CodeGenerator) GetModelsByTable() map[string]*ModelMetadata

func (*CodeGenerator) ValidateModels

func (g *CodeGenerator) ValidateModels() error

type ConstraintMetadata

type ConstraintMetadata struct {
	Name       string // Constraint name
	Type       string // Constraint type (CHECK, FOREIGN KEY, etc.)
	Definition string // Constraint definition
}

ConstraintMetadata represents constraint metadata

type FieldMetadata

type FieldMetadata struct {
	Name            string            // Go field name
	Type            string            // Go type
	DBName          string            // Database column name
	DBType          string            // Database type
	IsPointer       bool              // Whether it's a pointer type
	IsArray         bool              // Whether it's an array/slice
	IsPrimaryKey    bool              // Whether it's a primary key
	IsUnique        bool              // Whether it has unique constraint
	IsRequired      bool              // Whether it's required (not null)
	IsAutoGenerated bool              // Whether it's auto-generated (serial, default:now(), etc)
	DefaultValue    string            // Default value
	Tags            map[string]string // All struct tags
	DBDef           map[string]string // Parsed dbdef tags
	Relationship    *ParsedORMTag     // Parsed ORM relationship tag
}

FieldMetadata represents metadata about a struct field for code generation

type GenerationConfig

type GenerationConfig struct {
	PackageName  string   // Package name for generated code
	OutputDir    string   // Output directory
	Models       []string // Model names to generate (empty = all)
	Features     []string // Features to generate (columns, repositories, etc.)
	TemplateDir  string   // Custom template directory
	FileHeader   string   // Custom file header
	IncludeTests bool     // Whether to generate tests
	IncludeDocs  bool     // Whether to generate documentation
}

GenerationConfig configures code generation

type IndexMetadata

type IndexMetadata struct {
	Name    string   // Index name
	Columns []string // Column names
	Unique  bool     // Whether it's a unique index
	Partial string   // Partial index condition
}

IndexMetadata represents index metadata

type ModelMetadata

type ModelMetadata struct {
	Name          string               // Struct name
	Package       string               // Package name
	TableName     string               // Database table name
	Fields        []FieldMetadata      // All fields
	Relationships []FieldMetadata      // Only relationship fields
	Columns       []FieldMetadata      // Only database columns
	PrimaryKeys   []string             // Primary key column names
	Indexes       []IndexMetadata      // Index definitions
	Constraints   []ConstraintMetadata // Constraint definitions
}

ModelMetadata represents metadata about a model for code generation

type ModelValidationError

type ModelValidationError struct {
	Type    string
	Field   string
	Message string
}

ModelValidationError represents a model validation error

func (ModelValidationError) Error

func (e ModelValidationError) Error() string

type ModelValidator

type ModelValidator struct {
	// contains filtered or unexported fields
}

ModelValidator validates ORM models

func NewModelValidator

func NewModelValidator() *ModelValidator

func (*ModelValidator) ValidateModel

func (v *ModelValidator) ValidateModel(modelType reflect.Type) ValidationResult

func (*ModelValidator) ValidateModels

func (v *ModelValidator) ValidateModels(models map[string]reflect.Type) ValidationResult

type ORMTagParser

type ORMTagParser struct {
	// contains filtered or unexported fields
}

ORMTagParser handles parsing of ORM-specific tags for code generation

func NewORMTagParser

func NewORMTagParser() *ORMTagParser

func (*ORMTagParser) ParseFieldFromAST

func (p *ORMTagParser) ParseFieldFromAST(field parser.FieldDefinition) (FieldMetadata, error)

func (*ORMTagParser) ParseModelFromTable

func (p *ORMTagParser) ParseModelFromTable(table parser.TableDefinition) (*ModelMetadata, error)

func (*ORMTagParser) ParseORMTag

func (p *ORMTagParser) ParseORMTag(tag string) (*ParsedORMTag, error)

type ParsedORMTag

type ParsedORMTag struct {
	Type        string   // "belongs_to", "has_one", "has_many", "has_many_through"
	Target      string   // Target model/table name
	ForeignKey  string   // Foreign key column
	SourceKey   string   // Source key column (for has_many)
	TargetKey   string   // Target key column (for belongs_to)
	JoinTable   string   // Join table for has_many_through
	SourceFK    string   // Source FK in join table
	TargetFK    string   // Target FK in join table
	Conditions  []string // Additional conditions
	OrderBy     string   // Default ordering
	Dependent   string   // Dependent action (destroy, delete, nullify)
	Inverse     string   // Inverse relationship name
	Polymorphic string   // Polymorphic association
	Through     string   // Through association
	Validate    bool     // Whether to validate association
	Autosave    bool     // Whether to autosave association
	Counter     string   // Counter cache column
	Raw         string   // Raw tag value
}

ParsedORMTag represents a parsed ORM tag

type StormTagParser

type StormTagParser = parser.StormTagParser

StormTagParser is an alias for the parser package's StormTagParser

type ValidationResult

type ValidationResult struct {
	Valid  bool
	Errors []ModelValidationError
}

ValidationResult contains validation results

func ValidateModelsFromDirectory

func ValidateModelsFromDirectory(packagePath string) ValidationResult

Jump to

Keyboard shortcuts

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