contract

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: 3 Imported by: 0

Documentation

Overview

Package contract validates each configured lifecycle operation against sqlc query metadata: the required command (:one, :execrows, ...), whether insert/update return the full persisted row via RETURNING, and whether a query's parameters and result columns can hydrate the fields it needs to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateOperation

func ValidateOperation(kind OperationKind, queryName string, queries []*pb.Query, path, context, model string) (*pb.Query, []diagnostics.Diagnostic)

ValidateOperation checks that queryName exists among queries and its command satisfies the requirement for kind (diagnostics-contract.md stages 4 and 6; FR-003, FR-004). It returns the matched query — nil on any failure — and the diagnostics produced.

Types

type OperationKind

type OperationKind string

OperationKind identifies one of a model's lifecycle operations (data-model.md "Lifecycle Operation").

const (
	Find    OperationKind = "find"
	Insert  OperationKind = "insert"
	Update  OperationKind = "update"
	Delete  OperationKind = "delete"
	Refresh OperationKind = "refresh"
	List    OperationKind = "list"
	Single  OperationKind = "single"
	Lookup  OperationKind = "lookup"
)
const (
	// LazyToOne is a belongs_to/has_one relation's lazy_query: exactly one
	// related row, or none.
	LazyToOne OperationKind = "relation_lazy_to_one"
	// LazyToMany is a has_many/many_to_many relation's lazy_query: any
	// number of related rows.
	LazyToMany OperationKind = "relation_lazy_to_many"
	// Eager is any relation kind's eager_query: a batch query returning
	// related rows for many parents at once.
	Eager OperationKind = "relation_eager"
	// Attach is a many-to-many relation's attach_query (standalone or via
	// sync_queries.attach): :exec and :execrows are equally acceptable —
	// there is no row-hydration need, only an affected-row-count option.
	Attach OperationKind = "relation_attach"
	// Detach is a many-to-many relation's detach_query (standalone or via
	// sync_queries.detach).
	Detach OperationKind = "relation_detach"
	// SyncList is a many-to-many relation's sync_queries.list: the
	// currently-attached related IDs for one parent.
	SyncList OperationKind = "relation_sync_list"
)

Relation operation kinds extend the lifecycle OperationKind table above with the command/cardinality requirements a relation's configured queries must satisfy (data-model.md "Relation Graph Validation" stage 7). ValidateOperation is reused as-is — it was already generic over any OperationKind present in the requirements table.

Jump to

Keyboard shortcuts

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