Documentation
¶
Index ¶
Constants ¶
const Version = "v1.0.0"
Variables ¶
This section is empty.
Functions ¶
func GenerateFile ¶
func GenerateRelationsFile ¶ added in v0.2.0
GenerateRelationsFile generates relations_gen.go with all relation definitions
func ResolveRelationFields ¶ added in v0.3.0
func ResolveRelationFields(models []ModelMeta)
ResolveRelationFields resolves ForeignKeyField across models for hasOne/hasMany relations. For belongsTo, ForeignKeyField is on the parent model (resolved during parsing). For hasOne/hasMany, ForeignKeyField is on the target model and needs cross-model lookup.
Types ¶
type GenConfig ¶
type GenConfig struct {
OutPath string
IncludeStructs []string
ExcludeStructs []string
FieldTypeMap map[string]string
}
GenConfig holds parsed configuration from config.go
func ParseConfig ¶
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
Relations []RelationMeta // Relation definitions
Doc []string // Documentation comments
CliVersion string // SQLCLI Version
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
SoftDeleteField string // Name of the soft delete field (e.g. "DeletedAt")
SoftDeleteColumn string // Name of the soft delete column (e.g. "deleted_at")
SoftDeleteFieldType string // Type of the soft delete field (e.g. "*time.Time")
TypeAliases map[string]string // type A int → {"A": "int"}
FieldTypeMap map[string]string // User-defined type mappings from config
}
func ParseModels ¶
func (ModelMeta) GetFieldType ¶
GetFieldType returns the appropriate field type based on Go type
func (ModelMeta) GoIsNonZero ¶
GoIsNonZero returns the Go expression to check if a field is NOT zero value
func (ModelMeta) QualifyPKType ¶
QualifyPKType returns the qualified type name for the PK field
type RelationMeta ¶ added in v0.2.0
type RelationMeta struct {
FieldName string // Field name in parent model (e.g., "Posts")
RelType string // Relation type: "hasOne", "hasMany", "belongsTo"
ForeignKey string // Foreign key column (on child for hasOne/Many, on parent for belongsTo)
LocalKey string // Local key column (on parent for hasOne/Many[default id], on child for belongsTo[default id])
TargetType string // Target model type name (e.g., "Post")
TargetSlice bool // True if field is a slice (hasMany)
ForeignKeyField string // Go field name of foreign key (on parent for belongsTo, on target for hasOne/hasMany)
ForeignKeyFieldType string // Go type of FK field; set only if it differs from parent PK type (for type conversion)
TargetPKField string // Go field name of PK on target model (used for belongsTo getForeignKey)
}
RelationMeta holds information about a model relation