ormgen

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package ormgen writes the row scanners the ORM uses instead of reflection, and registers the models embedding orm.Model: one orm_scanners_gen.go per package that declares a model some orm.For[T]() names or that embeds orm.Model[T], its init calling orm.Register[T]() for the latter. orm generate (and the ormgen command, for go:generate) writes it to disk; the orm command's migration tool overlays it when it isn'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 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
	// 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