generator

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package generator writes the Go models of a dbspec document set; the orm-gen command and other programs call it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(options Options) ([]string, error)

Check generates the models like Generate without changing OutputDir or its parent directory and returns one line for each generated file that differs, is missing, or is extra, ordered by path.

func CheckSets added in v0.0.22

func CheckSets(sets []Options) ([]string, error)

CheckSets checks every set like Check, in the order GenerateSets uses, and returns the lines of every set's differences, each prefixed by its output directory.

func Generate

func Generate(options Options) error

Generate writes the Go models of the runtime model to OutputDir. The generated files of OutputDir are replaced after the scan converges; any other error leaves OutputDir unchanged. A *ScannedSourceError reports scanned packages that do not compile with the complete models written to OutputDir.

func GenerateSets added in v0.0.22

func GenerateSets(sets []Options) error

GenerateSets generates every set in an order that no set's scan needs a model of a set that is not generated yet. A set whose scanned packages import (directly or through other packages) the output package of another set is generated after that set; the other sets keep the order they are listed in. A cycle between sets has no such order and is refused, and the error names the sets of the cycle. The order of the list therefore does not matter. The first failed generation stops the run, as Generate does.

Types

type Options

type Options struct {
	// Model is the runtime model of a dbspec document set.
	Model     *runtimemodel.Model
	OutputDir string
	// PackageName selects the Go package name; the directory name by default.
	PackageName string
	// Scan lists the Go package patterns whose model calls are generated.
	Scan []string
}

Options describes one deterministic Go generation request.

type RefusedError added in v0.0.22

type RefusedError struct {
	Code string
	Text string
}

RefusedError is a refusal of the generator with its code of docs/spec/errors.yaml: a scan that does not parse or leaves a getter unattached (docs/spec/dsl.md, DSL-44 and DSL-152), and CONFIG for a name that the chain rules or the column name rules refuse (DSL-37, DSL-116, DSL-127, DSL-129 and DSL-130).

func (*RefusedError) Error added in v0.0.22

func (e *RefusedError) Error() string

type ScannedSourceError

type ScannedSourceError struct {
	Errors []string
}

ScannedSourceError reports scanned packages that do not compile with the generated models. The output directory holds the complete generated models when generation returns it.

func (*ScannedSourceError) Error

func (e *ScannedSourceError) Error() string

Jump to

Keyboard shortcuts

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