plan

package
v0.0.0-...-2de61a9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package plan builds the deterministic, order-preserved GenerationPlan (contexts -> models -> fields -> operations) from validated configuration, resolved field mappings, and contract-validated operations. Any error-severity diagnostic anywhere aborts plan construction entirely, which is the mechanism behind the generator's all-or-nothing guarantee.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParamBinding

type ParamBinding struct {
	Number int32
	Field  *ResolvedField
}

ParamBinding is one query parameter (by its 1-based positional Number) bound to the field that supplies its value at execution time.

type Plan

type Plan struct {
	Contexts []ResolvedContext
}

Plan is the fully-resolved, order-preserved, ready-to-render representation of one successful RootConfiguration (data-model.md "GenerationPlan").

func Build

Build constructs a GenerationPlan from validated configuration and the sqlc request's query metadata. Any error-severity diagnostic anywhere — from this stage or carried in from an earlier one — means Build returns a nil Plan: this is the mechanism behind FR-017's all-or-nothing guarantee.

type RelationParam

type RelationParam struct {
	Number int32
	// Name is the query parameter's own declared name (e.g. "published") —
	// also the key a scope method writes into the builder's scopeValues
	// map, so the two stay in sync regardless of the scope's own name.
	Name        string
	Source      RelationParamSource
	ParentField *ResolvedField  // set when Source == ParamFromParent
	ScopeName   string          // set when Source == ParamFromScope: the scope name whose Default/type this parameter uses
	Default     json.RawMessage // set when Source == ParamFromScope and a default was configured
	GoType      mapping.GoType  // the parameter's resolved Go type
}

RelationParam is one of LazyQuery's declared parameters, resolved to its binding source, in the query's own positional order.

type RelationParamSource

type RelationParamSource int

RelationParamSource identifies where a lazy_query parameter's value comes from at call time (data-model.md "ParameterBinding").

const (
	// ParamFromParent binds the parameter to a field on the parent model.
	ParamFromParent RelationParamSource = iota
	// ParamFromScope binds the parameter to whichever scope call (if any)
	// sets it in the current call chain, falling back to Default.
	ParamFromScope
)

type ResolvedContext

type ResolvedContext struct {
	Name      string
	Package   string
	Directory string
	Models    []ResolvedModel
}

ResolvedContext mirrors config.BoundedContext with every model resolved.

type ResolvedField

type ResolvedField struct {
	mapping.ResolvedField
	Policy config.FieldPolicy
}

ResolvedField is one field fully resolved: its mapping.ResolvedField (column/Go-type identity) plus the field policy governing its generated API surface.

type ResolvedLookup

type ResolvedLookup struct {
	Name      string
	QueryName string
	Operation *ResolvedOperation
}

type ResolvedModel

type ResolvedModel struct {
	Name       string
	Row        string
	Operations ResolvedOperations
	Fields     []ResolvedField
	Relations  []ResolvedRelation
	Queries    []ResolvedQuery
	Lookups    []ResolvedLookup
}

ResolvedModel mirrors config.ModelConfiguration with every operation and field resolved against real sqlc query metadata.

type ResolvedOperation

type ResolvedOperation struct {
	Kind      contract.OperationKind
	QueryName string
	Query     *pb.Query
	Params    []ParamBinding
	// Scan is the field to hydrate for each returned column, in the
	// query's own column order — this is the exact positional order a
	// generated Scan(...) call must use, which need not match the model's
	// declared field order. Empty for operations that don't return rows
	// (Delete via :execrows/:exec).
	Scan []*ResolvedField
}

ResolvedOperation is one lifecycle operation resolved to its concrete sqlc query, plus each of that query's parameters bound to the resolved field that supplies its value (stage 5, "parameter mapping validation").

type ResolvedOperations

type ResolvedOperations struct {
	Find    *ResolvedOperation
	Insert  *ResolvedOperation
	Update  *ResolvedOperation
	Delete  *ResolvedOperation
	Refresh *ResolvedOperation
}

ResolvedOperations holds the matched sqlc query for each configured lifecycle operation; a nil entry means that operation was not configured (no corresponding generated method), except Insert which config-stage validation guarantees is always present in a valid configuration.

type ResolvedQuery

type ResolvedQuery struct {
	Name      string
	Terminal  config.QueryTerminal
	Operation *ResolvedOperation
	Scopes    []ResolvedQueryScope
	Scan      []*ResolvedField
}

type ResolvedQueryScope

type ResolvedQueryScope struct {
	Name      string
	Parameter string
	Value     json.RawMessage
	ValueSet  bool
	Argument  string
	QueryName string
	Relation  string
	GoType    mapping.GoType
	Number    int32
	Variant   *pb.Query
}

type ResolvedRelation

type ResolvedRelation struct {
	Name        string
	Kind        config.RelationKind
	Target      *ResolvedModel
	Inverse     *ResolvedRelation
	LocalKey    *ResolvedField
	TargetKey   *ResolvedField
	ForeignKey  string
	Nullable    bool
	LazyQuery   *pb.Query
	EagerQuery  *pb.Query
	AttachQuery *pb.Query
	DetachQuery *pb.Query
	SyncList    *pb.Query
	SyncAttach  *pb.Query
	SyncDetach  *pb.Query
	Parameters  []config.ParameterBinding
	Scopes      []config.ScopeConfiguration
	// LazyParams is LazyQuery's declared parameters, resolved to their
	// binding source, in the query's own positional order.
	LazyParams []RelationParam
	// LazyScan/EagerScan are the target model's fields, in LazyQuery's/
	// EagerQuery's own returned-column order — the exact positional Scan(...)
	// order for hydrating a target instance from that query's result.
	LazyScan  []*ResolvedField
	EagerScan []*ResolvedField
	// ForeignKeyField is the target model's field matching ForeignKey,
	// resolved when EagerQuery is configured (needed to read each returned
	// row's grouping value for batch hydration).
	ForeignKeyField *ResolvedField
	// ScopeVariantQueries maps a query-variant scope's name to its already
	// command/cardinality-validated query (internal/relation's stage 8).
	ScopeVariantQueries map[string]*pb.Query
	// contains filtered or unexported fields
}

ResolvedRelation mirrors config.RelationConfiguration with every query and cross-model reference resolved against real sqlc metadata (data-model.md "ResolvedRelation").

Jump to

Keyboard shortcuts

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