generator

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildModelPath added in v0.37.2

func BuildModelPath(modelsDir, resourceName string) string

func ExtractTableNameOverride added in v0.37.2

func ExtractTableNameOverride(modelPath string, resourceName string) (string, bool)

ExtractTableNameOverride reads the actual table name from the bun.BaseModel tag in the generated entity struct. e.g.: bun.BaseModel `bun:"table:student_feedback"`

func ReadDIMode

func ReadDIMode() string

ReadDIMode reads the DI mode strategy from andurel.lock. Defaults to "manual" when not configured.

func ReadInertia added in v1.0.0

func ReadInertia() string

ReadInertia reads the inertia adapter from andurel.lock. Returns "" when not configured (templ-only mode).

func ReadNullType added in v1.0.0

func ReadNullType() string

ReadNullType reads the nullable type strategy from andurel.lock. Defaults to "sql.Null" when not configured.

func ResolveTableName added in v0.37.2

func ResolveTableName(modelsDir, resourceName string) string

func ResolveTableNameWithFlag added in v0.37.2

func ResolveTableNameWithFlag(modelsDir, resourceName string) (string, bool)

Types

type ConfigManager

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

ConfigManager manages configuration loading and validation

func GetGlobalConfigManager

func GetGlobalConfigManager() *ConfigManager

GetGlobalConfigManager returns the global configuration manager

func NewConfigManager

func NewConfigManager() *ConfigManager

NewConfigManager creates a new configuration manager

func (*ConfigManager) GetConfig

func (cm *ConfigManager) GetConfig() *UnifiedConfig

GetConfig returns the current configuration

func (*ConfigManager) Load

func (cm *ConfigManager) Load() (*UnifiedConfig, error)

Load loads configuration from defaults

type ConfigValidator

type ConfigValidator struct{}

ConfigValidator validates configuration values

func (*ConfigValidator) Validate

func (cv *ConfigValidator) Validate(config *UnifiedConfig) error

Validate validates the configuration

type ControllerConfig

type ControllerConfig struct {
	ResourceName string          `json:"resource_name"`
	PluralName   string          `json:"plural_name"`
	PackageName  string          `json:"package_name"`
	ModulePath   string          `json:"module_path"`
	Paths        ControllerPaths `json:"paths"`
}

type ControllerManager

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

func NewControllerManager

func NewControllerManager(
	validator *InputValidator,
	projectManager *ProjectManager,
	migrationManager *MigrationManager,
	config *UnifiedConfig,
) *ControllerManager

func (*ControllerManager) GenerateController

func (c *ControllerManager) GenerateController(
	resourceName, tableName string,
	withViews bool,
	inertia string,
) error

func (*ControllerManager) GenerateControllerFromModel

func (c *ControllerManager) GenerateControllerFromModel(resourceName string, withViews bool) error

func (*ControllerManager) GenerateControllerWithActions added in v1.0.0

func (c *ControllerManager) GenerateControllerWithActions(
	resourceName, tableName string,
	withViews bool,
	actions []string,
	inertia string,
) error

func (*ControllerManager) SetPrimaryKeyResolver added in v1.0.0

func (c *ControllerManager) SetPrimaryKeyResolver(resolver PrimaryKeyResolver)

type ControllerPaths

type ControllerPaths struct {
	Controllers string `json:"controllers"`
	Routes      string `json:"routes"`
}

type Coordinator

type Coordinator struct {
	ModelManager      *ModelManager
	ControllerManager *ControllerManager
	ViewManager       *ViewManager
	FragmentManager   *FragmentManager
	// contains filtered or unexported fields
}

func NewCoordinator

func NewCoordinator() (Coordinator, error)

func (*Coordinator) GenerateController

func (c *Coordinator) GenerateController(resourceName, tableName string, withViews bool, inertia string) error

GenerateController coordinates controller and optional view generation

func (*Coordinator) GenerateControllerFromModel

func (c *Coordinator) GenerateControllerFromModel(resourceName string, withViews bool) error

GenerateControllerFromModel coordinates controller and optional view generation from existing model

func (*Coordinator) GenerateControllerWithActions added in v1.0.0

func (c *Coordinator) GenerateControllerWithActions(resourceName, tableName string, withViews bool, actions []string, inertia string) error

func (*Coordinator) GenerateScaffold added in v1.0.0

func (c *Coordinator) GenerateScaffold(resourceName, tableName string, skipFactory bool, primaryKeyColumn string, inertia string) error

GenerateScaffold coordinates model, controller, and view generation for a complete resource scaffold.

type DatabaseConfig

type DatabaseConfig struct {
	Type          string   `yaml:"type"`
	MigrationDirs []string `yaml:"migration_dirs"`
	DefaultSchema string   `yaml:"default_schema"`
	Driver        string   `yaml:"driver"`
	Method        string   `yaml:"method"`
}

DatabaseConfig contains database-specific configuration

type DefaultPrimaryKeyResolver added in v1.0.0

type DefaultPrimaryKeyResolver struct{}

func (DefaultPrimaryKeyResolver) ConfirmNoPK added in v1.0.0

func (DefaultPrimaryKeyResolver) ConfirmNoPK(tableName string) (bool, error)

func (DefaultPrimaryKeyResolver) ResolveAlternatePK added in v1.0.0

func (DefaultPrimaryKeyResolver) ResolveAlternatePK(info PrimaryKeyInfo, tableName string) (PrimaryKeyInfo, error)

type FileConfig

type FileConfig struct {
	PrivatePermission os.FileMode `yaml:"private_permission"`
	DirPermission     os.FileMode `yaml:"dir_permission"`
}

FileConfig contains file-related configuration

type FragmentConfig

type FragmentConfig struct {
	ControllerName string // PascalCase, e.g. "Webhook"
	MethodName     string // PascalCase, e.g. "Validate"
	Path           string // Route path, e.g. "/validate" or "/:id/approve"
	HTTPMethod     string // HTTP method, e.g. "GET", "POST"
}

FragmentConfig holds the input configuration for fragment generation.

type FragmentManager

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

FragmentManager orchestrates fragment generation across controller, routes, and connect files.

func NewFragmentManager

func NewFragmentManager() *FragmentManager

NewFragmentManager creates a new FragmentManager.

func (*FragmentManager) GenerateFragment

func (fm *FragmentManager) GenerateFragment(config FragmentConfig) error

GenerateFragment validates inputs, resolves naming, and delegates to FragmentInjector for the three file modifications.

type GenerationConfig

type GenerationConfig struct {
	GenerateJSON bool   `yaml:"generate_json"`
	OutputFormat string `yaml:"output_format"`
}

GenerationConfig contains code generation configuration

type Generator

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

func New

func New() (Generator, error)

func (*Generator) ApplyModelUpdate added in v1.0.0

func (g *Generator) ApplyModelUpdate(result *UpdateModelResult) error

func (*Generator) GenerateController

func (g *Generator) GenerateController(resourceName, tableName string, withViews bool, inertia string) error

func (*Generator) GenerateControllerFromModel

func (g *Generator) GenerateControllerFromModel(resourceName string, withViews bool) error

func (*Generator) GenerateControllerWithActions added in v1.0.0

func (g *Generator) GenerateControllerWithActions(resourceName, tableName string, withViews bool, actions []string, inertia string) error

func (*Generator) GenerateFragment

func (g *Generator) GenerateFragment(config FragmentConfig) error

func (*Generator) GenerateModel

func (g *Generator) GenerateModel(resourceName string, tableNameOverride string, skipFactory bool) error

func (*Generator) GenerateModelWithPK added in v1.0.0

func (g *Generator) GenerateModelWithPK(resourceName string, tableNameOverride string, skipFactory bool, primaryKeyColumn string) error

func (*Generator) GenerateScaffold added in v1.0.0

func (g *Generator) GenerateScaffold(resourceName, tableName string, skipFactory bool, primaryKeyColumn string, inertia string) error

func (*Generator) GenerateView

func (g *Generator) GenerateView(resourceName, tableName string) error

func (*Generator) GenerateViewFromModel

func (g *Generator) GenerateViewFromModel(resourceName string, withController bool) error

func (*Generator) GetModulePath added in v1.0.0

func (g *Generator) GetModulePath() string

func (*Generator) SetControllerPKResolver added in v1.0.0

func (g *Generator) SetControllerPKResolver(resolver PrimaryKeyResolver)

func (*Generator) UpdateModel added in v1.0.0

func (g *Generator) UpdateModel(resourceName string) (*UpdateModelResult, error)

type InputValidator

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

func NewInputValidator

func NewInputValidator() *InputValidator

func (*InputValidator) ValidateAll

func (v *InputValidator) ValidateAll(resourceName, tableName, modulePath string) error

func (*InputValidator) ValidateFilePath

func (v *InputValidator) ValidateFilePath(filePath string) error

func (*InputValidator) ValidateModulePath

func (v *InputValidator) ValidateModulePath(modulePath string) error

func (*InputValidator) ValidateResourceName

func (v *InputValidator) ValidateResourceName(resourceName string) error

func (*InputValidator) ValidateTableName

func (v *InputValidator) ValidateTableName(tableName string) error

func (*InputValidator) ValidateTableNameOverride

func (v *InputValidator) ValidateTableNameOverride(resourceName, tableNameOverride string) error

type MigrationManager

type MigrationManager struct{}

func NewMigrationManager

func NewMigrationManager() *MigrationManager

func (*MigrationManager) BuildCatalogFromMigrations

func (mm *MigrationManager) BuildCatalogFromMigrations(
	tableName string,
	config *UnifiedConfig,
) (*catalog.Catalog, error)

type ModelConfig

type ModelConfig struct {
	TableName    string           `json:"table_name"`
	ResourceName string           `json:"resource_name"`
	PackageName  string           `json:"package_name"`
	DatabaseType string           `json:"database_type"`
	ModulePath   string           `json:"module_path"`
	Paths        ModelPaths       `json:"paths"`
	Generation   GenerationConfig `json:"generation"`
}

type ModelManager

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

func NewModelManager

func NewModelManager(
	validator *InputValidator,
	fileManager files.Manager,
	modelGenerator *models.Generator,
	projectManager *ProjectManager,
	migrationManager *MigrationManager,
	config *UnifiedConfig,
) *ModelManager

func (*ModelManager) ApplyModelUpdate added in v1.0.0

func (m *ModelManager) ApplyModelUpdate(result *UpdateModelResult) error

ApplyModelUpdate writes the updated model and factory file content and runs the Go formatter.

func (*ModelManager) GenerateModel

func (m *ModelManager) GenerateModel(
	resourceName string,
	tableNameOverride string,
	skipFactory bool,
	primaryKeyColumn string,
) error

func (*ModelManager) SetPrimaryKeyResolver added in v1.0.0

func (m *ModelManager) SetPrimaryKeyResolver(resolver PrimaryKeyResolver)

func (*ModelManager) UpdateModel added in v1.0.0

func (m *ModelManager) UpdateModel(resourceName string) (*UpdateModelResult, error)

UpdateModel inspects the existing model file for resourceName, rebuilds the Entity struct from migrations (preserving custom field types), and returns a result describing the change without writing anything.

type ModelPaths

type ModelPaths struct {
	Models string `json:"models"`
}

type NopPrimaryKeyResolver added in v1.0.0

type NopPrimaryKeyResolver struct{}

func (NopPrimaryKeyResolver) ConfirmNoPK added in v1.0.0

func (NopPrimaryKeyResolver) ConfirmNoPK(_ string) (bool, error)

func (NopPrimaryKeyResolver) ResolveAlternatePK added in v1.0.0

func (NopPrimaryKeyResolver) ResolveAlternatePK(info PrimaryKeyInfo, _ string) (PrimaryKeyInfo, error)

type PathConfig

type PathConfig struct {
	Models      string `yaml:"models"`
	Controllers string `yaml:"controllers"`
	Views       string `yaml:"views"`
	Routes      string `yaml:"routes"`
	Migrations  string `yaml:"migrations"`
	Database    string `yaml:"database"`
}

PathConfig contains path configurations

type PrimaryKeyInfo added in v1.0.0

type PrimaryKeyInfo struct {
	ColumnName      string // SQL column name (e.g., "id", "user_id")
	GoFieldName     string // Go struct field name (e.g., "ID", "UserID")
	DataType        string // SQL data type (e.g., "uuid", "bigint")
	GoType          string // Go type (e.g., "uuid.UUID", "int64")
	IsAutoIncrement bool
	Found           bool
	IsNamedID       bool // Whether the PK column is named "id"
}

func DetectPrimaryKey added in v1.0.0

func DetectPrimaryKey(cat *catalog.Catalog, tableName string) PrimaryKeyInfo

type PrimaryKeyResolver added in v1.0.0

type PrimaryKeyResolver interface {
	ResolveAlternatePK(info PrimaryKeyInfo, tableName string) (PrimaryKeyInfo, error)
	ConfirmNoPK(tableName string) (bool, error)
}

type ProjectConfig

type ProjectConfig struct {
	Name        string `yaml:"name"`
	ModulePath  string `yaml:"module_path"`
	PackageName string `yaml:"package_name"`
}

ProjectConfig contains project-specific configuration

type ProjectManager

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

func NewProjectManager

func NewProjectManager() (*ProjectManager, error)

func (*ProjectManager) GetModulePath

func (pm *ProjectManager) GetModulePath() string

type TemplateConfig

type TemplateConfig struct {
	CacheEnabled bool `yaml:"cache_enabled"`
	CacheTTL     int  `yaml:"cache_ttl"`
}

TemplateConfig contains template-related configuration

type UnifiedConfig

type UnifiedConfig struct {
	Database   DatabaseConfig   `yaml:"database"`
	Paths      PathConfig       `yaml:"paths"`
	Templates  TemplateConfig   `yaml:"templates"`
	Files      FileConfig       `yaml:"files"`
	Project    ProjectConfig    `yaml:"project"`
	Generation GenerationConfig `yaml:"generation"`
}

UnifiedConfig represents the single source of truth for all configuration

func GetGlobalConfig

func GetGlobalConfig() *UnifiedConfig

GetGlobalConfig returns the global configuration

func (*UnifiedConfig) GetControllerConfig

func (uc *UnifiedConfig) GetControllerConfig() ControllerConfig

GetControllerConfig returns configuration for controller generation

func (*UnifiedConfig) GetModelConfig

func (uc *UnifiedConfig) GetModelConfig() ModelConfig

GetModelConfig returns configuration for model generation

func (*UnifiedConfig) GetViewConfig

func (uc *UnifiedConfig) GetViewConfig() ViewConfig

GetViewConfig returns configuration for view generation

type UpdateModelResult added in v1.0.0

type UpdateModelResult struct {
	OldStruct      string
	NewStruct      string
	OldFileContent string
	NewFileContent string
	ModelPath      string
	HasChanges     bool

	FactoryPath       string
	OldFactoryContent string
	NewFactoryContent string
	FactoryHasChanges bool
}

UpdateModelResult holds the before/after state for a model update.

func (*UpdateModelResult) Diff added in v1.0.0

func (r *UpdateModelResult) Diff() (string, error)

Diff returns a unified diff of the struct definitions and method bodies (Entity, CreateData, UpdateData, Create, Update, Upsert). bun.BaseModel lines are excluded — their alignment changes with field widths and is not schema content.

func (*UpdateModelResult) FactoryDiff added in v1.0.0

func (r *UpdateModelResult) FactoryDiff() (string, error)

FactoryDiff returns a unified diff of the old vs new factory file content.

type ViewConfig

type ViewConfig struct {
	ResourceName string    `json:"resource_name"`
	PluralName   string    `json:"plural_name"`
	ModulePath   string    `json:"module_path"`
	Paths        ViewPaths `json:"paths"`
}

type ViewManager

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

func NewViewManager

func NewViewManager(
	validator *InputValidator,
	projectManager *ProjectManager,
	migrationManager *MigrationManager,
	viewGenerator *views.Generator,
	config *UnifiedConfig,
) *ViewManager

func (*ViewManager) GenerateView

func (v *ViewManager) GenerateView(resourceName, tableName string) error

func (*ViewManager) GenerateViewFromModel

func (v *ViewManager) GenerateViewFromModel(resourceName string, withController bool) error

func (*ViewManager) GenerateViewWithController

func (v *ViewManager) GenerateViewWithController(resourceName, tableName string, inertia string) error

func (*ViewManager) GenerateViewWithControllerActions added in v1.0.0

func (v *ViewManager) GenerateViewWithControllerActions(resourceName, tableName string, actions []string, inertia string) error

type ViewPaths

type ViewPaths struct {
	Views string `json:"views"`
}

Directories

Path Synopsis
internal
ddl

Jump to

Keyboard shortcuts

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