models

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BunModelConfig added in v1.0.0

type BunModelConfig struct {
	ResourceName  string
	TableName     string
	ModulePath    string
	PackageName   string
	UseSoftDelete bool // If true, use deleted_at for soft deletes
}

BunModelConfig holds configuration for bun model generation

type Config

type Config struct {
	TableName         string
	ResourceName      string
	PackageName       string
	DatabaseType      string
	ModulePath        string
	NullType          string
	CustomTypes       []types.TypeOverride
	PrimaryKeyColumn  string // Override PK column name (empty = auto-detect)
	GenerateWithoutPK bool   // Force generation without PK handling
}

Config controls model generation for a database table.

type FactoryField added in v1.0.0

type FactoryField struct {
	Name          string
	ArgumentName  string
	Type          string
	GoZero        string
	DefaultValue  string
	OptionName    string
	IsFK          bool
	IsTimestamp   bool
	IsID          bool
	IsAutoManaged bool
}

FactoryField represents a field in a factory

type GeneratedFactory added in v1.0.0

type GeneratedFactory struct {
	ModelName         string
	EntityName        string // ServerEntity (resource name + "Entity")
	NamespaceVar      string // Server (exported, package-scope)
	Package           string
	Fields            []FactoryField
	ModulePath        string
	StandardImports   []string
	ExternalImports   []string
	HasCreateFunction bool
	HasForeignKeys    bool           // True if there are 1+ FKs
	ForeignKeyFields  []FactoryField // All FK fields
	IDType            string         // "uuid.UUID", "int32", "int64", "string"
	IDGoFieldName     string         // Go field name for the primary key (e.g., "ID")
	IsAutoIncrementID bool           // True for serial/bigserial
	HasCreatedAt      bool
	HasUpdatedAt      bool
}

GeneratedFactory represents a factory for a model

type GeneratedField

type GeneratedField struct {
	Name         string
	Type         string
	Comment      string
	Package      string
	BunTag       string // Full bun struct tag (e.g., `bun:"id,pk,type:uuid"`)
	IsForeignKey bool
	IsNullable   bool
	IsPrimaryKey bool
}

GeneratedField describes one model field derived from a database column.

type GeneratedModel

type GeneratedModel struct {
	Name                string
	PluralName          string // The pluralized form of Name for function names (respects --table-name override)
	Package             string
	Fields              []GeneratedField
	StandardImports     []string
	ExternalImports     []string
	Imports             []string
	TableName           string
	TableNameOverride   string
	TableNameOverridden bool
	ModulePath          string
	DatabaseType        string
	IDType              string // "uuid.UUID", "int32", "int64", "string"
	IDGoType            string // Same as IDType (for template clarity)
	IsAutoIncrementID   bool   // True for serial/bigserial
	IDFieldName         string // SQL column name of PK (e.g., "id", "user_id")
	IDGoFieldName       string // Go struct field name of PK (e.g., "ID", "UserID")
	HasPrimaryKey       bool   // Whether the table has any primary key
	EntityName          string // ServerEntity (resource name + "Entity")
	NamespaceVar        string // Server (exported, package-scope)
	NamespaceType       string // server (unexported receiver type)
	ReceiverName        string // s (for the namespace methods)
	HasCreatedAt        bool
	HasUpdatedAt        bool
}

GeneratedModel contains the template data for a generated model file.

type Generator

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

Generator builds model template data and writes model files.

func NewGenerator

func NewGenerator(databaseType string) *Generator

NewGenerator creates a new generator.

func (*Generator) Build

func (g *Generator) Build(cat *catalog.Catalog, config Config) (*GeneratedModel, error)

Build converts catalog metadata and config into a generated model.

func (*Generator) BuildCatalogFromMigrations added in v1.0.0

func (g *Generator) BuildCatalogFromMigrations(tableName string, migrationDirs []string) (*catalog.Catalog, error)

BuildCatalogFromMigrations builds a catalog from migration files

func (*Generator) BuildFactory added in v1.0.0

func (g *Generator) BuildFactory(cat *catalog.Catalog, config Config, genModel *GeneratedModel) (*GeneratedFactory, error)

BuildFactory generates factory metadata from a model

func (*Generator) GenerateFactoryFile added in v1.0.0

func (g *Generator) GenerateFactoryFile(factory *GeneratedFactory, templateStr string) (string, error)

GenerateFactoryFile renders a factory file from a template

func (*Generator) GenerateModel

func (g *Generator) GenerateModel(
	cat *catalog.Catalog,
	resourceName string,
	pluralName string,
	modelPath string,
	modulePath string,
	tableNameOverride string,
	nullType string,
	primaryKeyColumn string,
	generateWithoutPK bool,
) error

GenerateModel renders and writes a model file for a resource.

func (*Generator) GenerateModelFile

func (g *Generator) GenerateModelFile(model *GeneratedModel, templateStr string) (string, error)

GenerateModelFile renders model template data into Go source.

func (*Generator) WriteFactoryFile added in v1.0.0

func (g *Generator) WriteFactoryFile(factory *GeneratedFactory, outputDir string) error

WriteFactoryFile writes a factory file to disk

Jump to

Keyboard shortcuts

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