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
- func EmbedsModel(n *types.Named) bool
- func FieldsName(file string) string
- func Generate(dir string, c Config) (map[string][]byte, error)
- func Missing(dir string, c Config) (map[string][]byte, error)
- func Packages(dir string) ([]string, error)
- func Write(dir string, c Config, check bool) ([]string, error)
- type Config
Constants ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
Packages is the patterns (./dir) of the packages under dir that may declare models with orm.For or orm.Model.
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.