ormc

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldInfo

type FieldInfo struct {
	Name       string
	ColumnName string
	Type       fmt.FieldType
	PK         bool
	Unique     bool
	NotNull    bool
	AutoInc    bool
	Ref        string
	RefColumn  string
	IsPK       bool
	OldName    string
	GoType     string
	OmitEmpty  bool
	// Permitted config — populated from validate:"..." tag
	Letters           bool
	Tilde             bool
	Numbers           bool
	Spaces            bool
	Extra             []rune
	Minimum           int
	Maximum           int
	WidgetConstructor string   // e.g. "input.Text()"
	Tags              []string // input modifiers e.g. "notilde", "min=2"
}

type Generator

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

Ormc is the code generator handler for the ormc tool.

func New

func New() *Generator

NewOrmc creates a new Ormc handler with rootDir defaulting to ".".

func (*Generator) GenerateForFile

func (o *Generator) GenerateForFile(infos []StructInfo, sourceFile string) error

GenerateForFile writes ORM implementations for all infos into one file.

func (*Generator) GenerateForStruct

func (g *Generator) GenerateForStruct(structName string, goFile string) error

GenerateForStruct reads the Go File and generates the ORM implementations for a given struct name.

func (*Generator) MainInputFileRelativePath

func (g *Generator) MainInputFileRelativePath() string

MainInputFileRelativePath returns the relative path to the main input file, if any.

func (*Generator) Name added in v0.9.4

func (g *Generator) Name() string

Name returns the TUI handler label shown in the development console.

func (*Generator) NewFileEvent

func (g *Generator) NewFileEvent(fileName, extension, filePath, event string) error

NewFileEvent implements the file-event contract for watchers (e.g. tinywasm/app's devwatch).

func (*Generator) ParseStruct

func (g *Generator) ParseStruct(structName string, goFile string) (StructInfo, error)

ParseStruct parses a single struct from a Go file and returns its metadata.

func (*Generator) ResolveRelations

func (o *Generator) ResolveRelations(all map[string]StructInfo)

ResolveRelations (exported for testing) scans all parent SliceFields, finds the matching FK in the child struct, and appends RelationInfo to the child's entry in the map.

func (*Generator) RewriteModelTags

func (o *Generator) RewriteModelTags(path string) error

RewriteModelTags performs in-place struct tag cleanup in the given file. It removes 'form' and 'validate' tags, and strips field names from 'json' tags. For ormc:formonly structs, json field names are preserved (needed for camelCase protocols).

func (*Generator) Run

func (g *Generator) Run() error

Run is the entry point for the CLI tool.

func (*Generator) ScanModules

func (g *Generator) ScanModules(rootDir string) error

ScanModules syncs the DB schema of every discovered module to the injected SchemaSyncer. Called once at startup by the tool (app), after SetSyncer.

  • Writable module (main / replace): regenerate <file>_orm.go from model.go, then sync each DB struct.
  • Read-only module (cache): parse the committed model_orm.go, then sync.

No-op if no syncer is injected (CLI codegen-only path).

func (*Generator) SetFinder

func (g *Generator) SetFinder(f *modfind.Finder)

SetFinder injects the shared modfind.Finder (one go list across ssr/image/ormc).

func (*Generator) SetLog

func (g *Generator) SetLog(fn func(messages ...any))

SetLog sets the log function for warnings and informational messages. If not set, messages are silently discarded.

func (*Generator) SetRootDir

func (g *Generator) SetRootDir(dir string)

SetRootDir sets the root directory that Run() will scan. Defaults to ".". Useful in tests to point to a specific directory without needing os.Chdir.

func (*Generator) SetSkipTidy

func (g *Generator) SetSkipTidy(skip bool)

SetSkipTidy enables or disables the go mod tidy pass.

func (*Generator) SetSyncer

func (g *Generator) SetSyncer(s SchemaSyncer)

SetSyncer sets the schema syncer for the generator.

func (*Generator) SupportedExtensions

func (g *Generator) SupportedExtensions() []string

SupportedExtensions returns the list of file extensions this generator handles.

func (*Generator) UnobservedFiles

func (g *Generator) UnobservedFiles() []string

UnobservedFiles returns a list of files that should be ignored by the watcher.

type RelationInfo

type RelationInfo struct {
	ChildStruct        string // e.g. "Role"
	FKField            string // e.g. "UserID"  (Go field name)
	FKColumn           string // e.g. "user_id" (column name)
	LoaderName         string // e.g. "ReadAllRoleByUserID"
	FKFieldType        string // e.g. "string", "int64"
	UseFieldDescriptor bool   // child has // orm:typed_fields: use ChildStruct_.FKField
}

RelationInfo describes a one-to-many relation loader to generate.

type SchemaSyncer

type SchemaSyncer interface {
	SyncSchema(table string, fields []fmt.Field) error
}

SchemaSyncer applies a parsed table schema. Implemented by the consumer (tinywasm/app) over *orm.DB; ormc only ever sees this interface.

type SliceFieldInfo

type SliceFieldInfo struct {
	Name     string // e.g. "Roles"
	ElemType string // e.g. "Role"
}

SliceFieldInfo records a slice-of-struct field found in a parent struct. Not DB-mapped; used only for relation resolution.

type StructInfo

type StructInfo struct {
	Name              string
	ModelName         string
	PackageName       string
	Fields            []FieldInfo
	ModelNameDeclared bool
	IsForm            bool
	NoDB              bool
	WantTypedFields   bool
	SourceFile        string
	SliceFields       []SliceFieldInfo // populated by ParseStruct; used by ResolveRelations
	Relations         []RelationInfo   // populated by ResolveRelations; used by GenerateForFile
}

Jump to

Keyboard shortcuts

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