planner

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlueprintDef

type BlueprintDef struct {
	Name      string
	Table     string
	PKFields  []string
	Relations []RelationDef
	Defaults  func() any
	Insert    func(ctx context.Context, db, v any) (any, error)
	Delete    func(ctx context.Context, db, v any) error
	ModelType reflect.Type
}

BlueprintDef is the planner's view of a registered blueprint.

type GenerateFn

type GenerateFn func(r *rand.Rand, value any) (any, error)

type OptionSet

type OptionSet struct {
	Sets    map[string]any                     // field name → value
	Uses    map[string]any                     // relation name → existing value
	Refs    map[string]*OptionSet              // relation name → nested options
	Omits   map[string]bool                    // relation name → true
	Whens   map[string]func(any) (bool, error) // relation name → dynamic expansion predicate
	WithFns []WithFn                           // typed root mutators
	Seqs    map[string]any                     // field name → func(int) any (sequence generators)
	GenFns  []GenerateFn                       // typed rand-driven mutators
	Rand    *rand.Rand                         // RNG used by GenFns
	Only    map[string]bool                    // nil = expand all; non-nil = lazy mode (root-level relation filter)
}

OptionSet holds parsed options for a single node.

type PlanManyResult

type PlanManyResult struct {
	Graph   *graph.Graph
	RootIDs []string
}

PlanManyResult is the output of the batch planner.

func PlanMany

func PlanMany(reg Registry, rootType reflect.Type, opts []*OptionSet) (*PlanManyResult, error)

PlanMany builds a dependency graph for multiple roots of the same type.

type PlanResult

type PlanResult struct {
	Graph *graph.Graph
}

PlanResult is the output of the planner.

func Plan

func Plan(reg Registry, rootType reflect.Type, opts *OptionSet) (*PlanResult, error)

Plan builds a dependency graph for the given root type with options.

type Registry

type Registry interface {
	LookupByName(name string) (*BlueprintDef, error)
	LookupByType(t reflect.Type) (*BlueprintDef, error)
}

Registry is the interface the planner uses to look up blueprints.

type RelationDef

type RelationDef struct {
	Name             string
	Kind             RelationKind
	LocalFields      []string
	RefBlueprint     string
	ThroughBlueprint string
	RemoteFields     []string
	Required         bool
	Count            int            // For has_many/many_to_many: number of records to create (default 1)
	When             func(any) bool // Optional predicate: expand only when true
}

RelationDef is the planner's view of a relation.

type RelationKind

type RelationKind string

RelationKind is the planner's canonical relation kind.

const (
	BelongsTo  RelationKind = "belongs_to"
	HasMany    RelationKind = "has_many"
	ManyToMany RelationKind = "many_to_many"
)

type WithFn

type WithFn func(value any) (any, error)

Jump to

Keyboard shortcuts

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