storagegen

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package storagegen holds engine-neutral helpers shared by the storage code generators (protoc-gen-ent and, per F027, protoc-gen-storage). Its job is to make the "can this resource field be deterministically wired into a persistence.Repository adapter?" decision IDENTICALLY across backends — so a resource behaves the same on ent and GORM, and a field the generator cannot map fails generation on both rather than being silently dropped (F027 G-002 fail-closed, G-005 cross-backend parity).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mappable

func Mappable(f Field) bool

Mappable reports whether a field can be deterministically wired into a repository adapter (its setter, projection, and — where relevant — filter column). A field that is not Mappable has no automatic representation and must be surfaced to the developer, not dropped.

The order matters: a relationship is mappable even though it is a message or repeated field (it becomes an edge/association); only NON-relationship messages, repeated fields, and enums are unmappable.

func Reason

func Reason(f Field) string

Reason returns a human-actionable explanation (with the remedy) for why a field is unmapped. Only meaningful for fields where Mappable is false.

Types

type Field

type Field struct {
	Name           string // proto field name (e.g. "fleet_id")
	IsID           bool   // the resource primary key
	IsTenant       bool   // account_id (supplied by the tenant mixin)
	IsSecret       bool   // secret field (stored hash+cipher)
	IsCredential   bool   // verify-only credential field (stored public_id + salted hash)
	IsTags         bool   // map<string,string> (stored as a JSON column)
	OutputOnly     bool   // AIP-203 OUTPUT_ONLY (surfaced on read, never written)
	IsRepeated     bool   // a repeated (list) field
	IsMessage      bool   // a nested message field (NOT a string map)
	IsEnum         bool   // an enum field
	IsRelationship bool   // carries a has_one/has_many/belongs_to/many_to_many annotation
	IsScalarFK     bool   // a scalar that is some relationship's foreign_key
	HasColumnType  bool   // maps to a recognized scalar column type (string/int/bool/bytes/…)
}

Field is the engine-neutral view of a proto resource field that the storage generators classify. Both plugins populate it from the same proto annotations (field.v1 options + field_behavior + descriptor kind), so classification does not depend on any ent- or GORM-specific type.

func Classify

func Classify(fields []Field) (auto, unmapped []Field)

Classify partitions fields into those the generator can wire automatically and those it cannot. Callers must fail generation when unmapped is non-empty.

Jump to

Keyboard shortcuts

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