Documentation
¶
Index ¶
- func EmitDBFile(models []ModelInfo, dbPkgName string) string
- func EmitModelFile(m ModelInfo) string
- func EmitModelFileChecked(m ModelInfo) (string, error)
- func Generate(configPath string) error
- func GenerateCreateTable(m ModelInfo, fks map[string]string) string
- func GenerateDropSchema(models []ModelInfo) string
- func GenerateSchema(models []ModelInfo) string
- func GoTypeToSQL(goType string) string
- type Config
- type FieldInfo
- type ModelInfo
- type OutputConfig
- type RelationFieldInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmitDBFile ¶
EmitDBFile generates the aggregated DB struct file that wires up all repositories. dbPkgName is the Go package name for the output file (e.g. "db").
func EmitModelFile ¶
EmitModelFile generates the complete per-model _drel.go file content.
func EmitModelFileChecked ¶
EmitModelFileChecked generates the per-model file, returning an error if the model uses unsupported features.
func Generate ¶
Generate runs the full code generation pipeline: loads config, scans packages, emits per-model files, and emits the aggregated DB file.
func GenerateCreateTable ¶
GenerateCreateTable emits a CREATE TABLE statement for a single model. fks maps column names to referenced table names for foreign key constraints.
func GenerateDropSchema ¶
GenerateDropSchema emits DROP TABLE statements in reverse order to respect foreign key dependencies.
func GenerateSchema ¶
GenerateSchema emits the full schema DDL for a slice of models, including enum type definitions, foreign key constraints, and many-to-many pivot tables.
func GoTypeToSQL ¶
GoTypeToSQL maps a Go type string to its corresponding Postgres SQL type. Pointer types are unwrapped to their base type. Unknown types default to "text".
Types ¶
type Config ¶
type Config struct {
Packages []string `yaml:"packages"`
Output OutputConfig `yaml:"output"`
Dialect string `yaml:"dialect"`
}
func LoadConfig ¶
type FieldInfo ¶
type FieldInfo struct {
Name string
GoType string
ColumnName string
IsExported bool
RelTag string
Relation *RelationFieldInfo
IsVO bool // implements sql.Scanner + driver.Valuer (single-column VO)
IsMultiColVO bool // implements drel.MultiColumnMapper (multi-column VO)
MultiColPrefix string // db tag used as column prefix for multi-column VOs
LocalGoType string // type name without package qualifier, for same-package generated code
TypePkgPath string // import path of the field type's package (empty for primitives/same-package)
IsPointer bool // whether the field is a pointer type
IsEnum bool
EnumValues []string
}
type ModelInfo ¶
type ModelInfo struct {
Name string
PkgPath string
PkgName string
PKType string // display type for generated code (e.g., "int", "uuid.UUID")
PKTypeFull string // fully qualified (e.g., "github.com/google/uuid.UUID")
PKTypePkg string // import path for external PK types (empty for primitives)
TableName string
Fields []FieldInfo
HasSoftDelete bool
HasVersioned bool
HasAudit bool
Dir string // filesystem directory of the package
}
type OutputConfig ¶
type RelationFieldInfo ¶
type RelationFieldInfo struct {
Type string // "has_many", "has_one", "belongs_to", "many_to_many"
FK string // foreign key column
JoinTable string // for many_to_many
RefColumn string // target FK column in pivot table (many-to-many)
TargetModel string // target model name for foreign key resolution
}
RelationFieldInfo holds parsed relationship metadata from a `rel:"..."` struct tag.