Documentation
¶
Overview ¶
Package config decodes and validates the plugin's `options` block: schema version gating, bounded-context/model/field structural validation, and order-preserving decode of the declaration-ordered `models` and `fields` objects.
Index ¶
- Constants
- func DecodeStrict(data []byte, v any) error
- type BoundedContext
- type FieldPolicy
- type GeneratedKind
- type LookupOperation
- type ModelConfiguration
- type Operations
- type OrderedEntry
- type OrderedObject
- type ParameterBinding
- type QueryConfiguration
- type QueryScope
- type QueryTerminal
- type RelationConfiguration
- type RelationKind
- type RootConfiguration
- type ScopeConfiguration
- type SqlcTarget
- type SyncQueries
- type ValueObjectMapping
Constants ¶
const SupportedVersion = 1
SupportedVersion is the only configuration schema version this generator accepts (FR-008). There is exactly one supported version for this initial baseline; see contracts/config.schema.json.
Variables ¶
This section is empty.
Functions ¶
func DecodeStrict ¶
DecodeStrict decodes v from data, rejecting any JSON object field with no corresponding struct field (the equivalent of the config schema's `additionalProperties: false`).
Types ¶
type BoundedContext ¶
type BoundedContext struct {
Name string
Package string
Directory string
Models []ModelConfiguration
}
BoundedContext is a named grouping of related models sharing one Go package and output directory (data-model.md "BoundedContext").
type FieldPolicy ¶
type FieldPolicy struct {
Name string
Readable bool
Fillable bool
Mutable bool
Generated GeneratedKind
ImmutableAfterInsert bool
Sensitive bool
Version bool
// Column and RowField are explicit overrides; empty means "resolve
// automatically" (internal/mapping's responsibility).
Column string
RowField string
ValueObject *ValueObjectMapping
}
FieldPolicy is the per-column configuration described by FR-005: what API surface a field gets, how it's populated, and how it's treated in diagnostics.
type GeneratedKind ¶
type GeneratedKind int
GeneratedKind describes when a field's value is supplied by the database rather than the caller.
const ( // GeneratedNone means the field is not database-generated. GeneratedNone GeneratedKind = iota // GeneratedInsert means the field is populated only from the insert // operation's RETURNING row. GeneratedInsert // GeneratedSave means the field may be repopulated on both insert and // update. GeneratedSave )
type LookupOperation ¶
type ModelConfiguration ¶
type ModelConfiguration struct {
Name string
Row string
Operations Operations
Fields []FieldPolicy
Relations []RelationConfiguration
Queries []QueryConfiguration
Lookups []LookupOperation
}
ModelConfiguration is the mapping for one database entity: its canonical sqlc row/result type, its lifecycle-operation-to-query mapping, and its field policies (data-model.md "ModelConfiguration").
type Operations ¶
Operations maps each lifecycle operation kind to the sqlc query name that implements it. An empty string means that operation was not configured (no corresponding generated method); Insert is the only operation required to be non-empty.
type OrderedEntry ¶
type OrderedEntry struct {
Key string
Value json.RawMessage
}
OrderedEntry is one key/value pair from a JSON object, in declaration order.
type OrderedObject ¶
type OrderedObject []OrderedEntry
OrderedObject decodes a JSON object while preserving the declaration order of its keys — standard map[string]T decoding loses this order, which would violate FR-018/FR-011's requirement that `contexts[].models` and `fields` be processed in the order the developer wrote them (see research.md "Declaration-order determinism").
func (*OrderedObject) UnmarshalJSON ¶
func (o *OrderedObject) UnmarshalJSON(data []byte) error
type ParameterBinding ¶
type ParameterBinding struct {
// Name is the query parameter name this binding supplies (map key).
Name string
// Source is either "parent.<key>" or "scope.<ScopeName>", unparsed.
Source string
// Default is the raw JSON default value; DefaultSet is false when no
// default was configured.
Default json.RawMessage
DefaultSet bool
}
ParameterBinding is one entry in a relation's `parameters` map: how one sqlc query parameter gets its value at call time (data-model.md "ParameterBinding").
type QueryConfiguration ¶
type QueryConfiguration struct {
Name string
Operation string
Terminal QueryTerminal
Scopes []QueryScope
}
type QueryScope ¶
type QueryTerminal ¶
type QueryTerminal string
const ( QueryTerminalGet QueryTerminal = "get" QueryTerminalFirst QueryTerminal = "first" QueryTerminalFind QueryTerminal = "find" QueryTerminalDelete QueryTerminal = "delete" QueryTerminalRefresh QueryTerminal = "refresh" )
type RelationConfiguration ¶
type RelationConfiguration struct {
Name string
Kind RelationKind
Model string
LocalKey string
ForeignKey string
// TargetKey identifies the target model's own field used to bind
// many-to-many pivot queries (attach_query/detach_query's second
// parameter, sync_queries.list's diff key) — required only when a
// many_to_many relation configures Attach/Detach/Sync. Not part of the
// original relations.schema.json sketch; added during implementation
// once many-to-many pivot parameter binding needed an explicit target-
// side field, the same way local_key already identifies the parent
// side.
TargetKey string
Nullable bool
Inverse string
LazyQuery string
EagerQuery string
AttachQuery string
DetachQuery string
SyncQueries *SyncQueries
Parameters []ParameterBinding
Scopes []ScopeConfiguration
}
RelationConfiguration is one named relation declared on a model (data-model.md "RelationConfiguration", Key Entity in spec).
type RelationKind ¶
type RelationKind string
RelationKind identifies one of a relation's four supported shapes (data-model.md "RelationConfiguration", FR-001).
const ( BelongsTo RelationKind = "belongs_to" HasMany RelationKind = "has_many" HasOne RelationKind = "has_one" ManyToMany RelationKind = "many_to_many" )
type RootConfiguration ¶
type RootConfiguration struct {
Version int
Sqlc SqlcTarget
Contexts []BoundedContext
}
RootConfiguration is the top-level `options` value passed to the plugin (data-model.md "RootConfiguration").
func Decode ¶
func Decode(pluginOptions []byte) (*RootConfiguration, []diagnostics.Diagnostic)
Decode parses and validates the plugin's raw `options` bytes into a RootConfiguration, collecting diagnostics across every structural validation stage. The caller (internal/generate) is responsible for checking diagnostics.HasError before proceeding to the next pipeline stage or emitting any output (FR-017).
type ScopeConfiguration ¶
type ScopeConfiguration struct {
Name string
Parameter string
// Value is the raw JSON fixed value for a fixed-value scope; ValueSet
// distinguishes "unset" from a legitimate JSON `null`/`false`/`0`.
Value json.RawMessage
ValueSet bool
// Argument is the declared Go type name for a developer-supplied-value
// scope; empty means unset.
Argument string
// Query names an alternate configured query for a query-variant scope;
// empty means unset.
Query string
}
ScopeConfiguration is a named, reusable constraint on a relation (data-model.md "ScopeConfiguration").
type SqlcTarget ¶
SqlcTarget identifies the sqlc-gen-go output the generated code will import (data-model.md "SqlcTarget").
type SyncQueries ¶
SyncQueries names the three queries backing a many-to-many relation's Sync operation: list currently-attached related IDs, then attach/detach the diff (data-model.md "RelationConfiguration.sync_queries").
type ValueObjectMapping ¶
ValueObjectMapping describes the explicit conversion between a generated model field type and its sqlc-compatible persisted column type.