ormgen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ormgen writes the row scanners the ORM uses instead of reflection, registers the models embedding orm.Model, and writes each model's typed fields. A package that declares a model some orm.For[T]() names or that embeds orm.Model[T] gets one orm_scanners_gen.go, its init calling orm.Register[T]() for the latter; the models declared in post.go get their typed fields (PostFields, PostPath) in post_gen.go. orm generate (and the ormgen command, for go:generate) writes them to disk; the orm command's migration tool overlays them when they aren't there.

Index

Constants

View Source
const (
	OutName      = "orm_scanners_gen.go"
	OutTestName  = "orm_scanners_gen_test.go"
	OutXTestName = "orm_scanners_x_gen_test.go" // a package_test package
)

The files ormgen writes in a model's package: OutTestName for models declared in _test.go files.

Variables

This section is empty.

Functions

func EmbedsModel

func EmbedsModel(n *types.Named) bool

EmbedsModel is whether n is a model of its own orm.Model: a struct embedding orm.Model[n], directly or through embedded structs (by pointer or twice too: Register then fails boot saying why). A struct holding another model's orm.Model (one embedding a model to add fields) isn't one.

func FieldsName added in v1.0.0

func FieldsName(file string) string

FieldsName is the file holding the typed fields of the models declared in file: post.go's in post_gen.go, post_test.go's in post_gen_test.go, and a .vuka file's (post.vuka, transpiled to post_vuka.go) in post_gen.go.

func Generate

func Generate(dir string, c Config) (map[string][]byte, error)

Generate is the scanner files of the models the packages under dir name with orm.For or declare embedding orm.Model, by path.

func Missing

func Missing(dir string, c Config) (map[string][]byte, error)

Missing is the files Generate makes under dir that the tree lacks or holds out of date: what a tool overlays onto a build so the models are registered and scanned without the files being written.

func Packages

func Packages(dir string) ([]string, error)

Packages is the patterns (./dir) of the packages under dir that may declare models with orm.For or orm.Model.

func Write

func Write(dir string, c Config, check bool) ([]string, error)

Write writes the files Generate makes under dir that differ from what is on disk, and returns their paths; with check it writes nothing and returns the paths that are out of date. For tools: orm generate and the ormgen command are this.

Types

type Config

type Config struct {
	Patterns []string
	Tests    bool
	// Overlay is source the packages hold that the tree doesn't, by
	// absolute path, as go/packages takes it: what a tool generated, such
	// as the Go of .vuka files.
	Overlay map[string][]byte
	// Skipped hears each model no code is generated for, and why: it is
	// read by reflection at run time instead.
	Skipped func(model, reason string)
}

Config is what Generate loads: Patterns (default ./...), and Tests to take the models of test files too.

Jump to

Keyboard shortcuts

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