model

package
v1.6.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Package model provides model registration and metadata management for TableTheory

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldMetadata

type FieldMetadata struct {
	Type        reflect.Type
	IndexInfo   map[string]IndexRole
	Tags        map[string]string
	DBName      string
	Name        string
	IndexPath   []int
	Index       int
	IsPK        bool
	IsEncrypted bool
	IsVersion   bool
	IsTTL       bool
	IsCreatedAt bool
	IsUpdatedAt bool
	IsSet       bool
	OmitEmpty   bool
	IsSK        bool
}

FieldMetadata holds metadata for a single field

type IndexRole

type IndexRole struct {
	IndexName string
	IsPK      bool
	IsSK      bool
}

IndexRole represents a field's role in an index

type IndexSchema

type IndexSchema struct {
	Name            string
	Type            IndexType
	PartitionKey    *FieldMetadata
	SortKey         *FieldMetadata
	ProjectionType  string
	ProjectedFields []string
	Sparse          bool
}

IndexSchema represents a GSI or LSI schema

type IndexType

type IndexType string

IndexType represents the type of index

const (
	GlobalSecondaryIndex IndexType = "GSI"
	LocalSecondaryIndex  IndexType = "LSI"
)

type KeySchema

type KeySchema struct {
	PartitionKey *FieldMetadata
	SortKey      *FieldMetadata
}

KeySchema represents a primary key or index key schema

type Metadata

type Metadata struct {
	Type             reflect.Type
	PrimaryKey       *KeySchema
	Fields           map[string]*FieldMetadata
	FieldsByDBName   map[string]*FieldMetadata
	VersionField     *FieldMetadata
	TTLField         *FieldMetadata
	CreatedAtField   *FieldMetadata
	UpdatedAtField   *FieldMetadata
	TableName        string
	Indexes          []IndexSchema
	WritePolicy      WritePolicy
	NamingConvention naming.Convention
}

Metadata holds all metadata for a model

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages registered models and their metadata

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new model registry

func (*Registry) GetMetadata

func (r *Registry) GetMetadata(model any) (*Metadata, error)

GetMetadata retrieves metadata for a model

func (*Registry) GetMetadataByTable

func (r *Registry) GetMetadataByTable(tableName string) (*Metadata, error)

GetMetadataByTable retrieves metadata by table name

func (*Registry) Register

func (r *Registry) Register(model any) error

Register registers a model and parses its metadata

type WritePolicy added in v1.7.0

type WritePolicy struct {
	Mode                WritePolicyMode
	ProtectedAttributes []string
}

WritePolicy declares opt-in model-level mutation guardrails.

The zero value is equivalent to Mutable with no protected attributes. ProtectedAttributes are normalized by Metadata parsing to canonical DynamoDB attribute names.

func DefaultWritePolicy added in v1.7.0

func DefaultWritePolicy() WritePolicy

DefaultWritePolicy returns the default mutation policy for models that do not opt into write_policy metadata.

type WritePolicyMode added in v1.7.0

type WritePolicyMode string

WritePolicyMode describes how high-level write APIs may mutate a model.

const (
	// WritePolicyModeMutable preserves the historical TableTheory behavior:
	// create, update, upsert, and delete operations are allowed unless other
	// model metadata or call-level conditions reject them.
	WritePolicyModeMutable WritePolicyMode = "mutable"

	// WritePolicyModeWriteOnce permits initial creation but rejects generic
	// high-level mutation APIs such as update, upsert, and delete.
	WritePolicyModeWriteOnce WritePolicyMode = "write_once"
)

Jump to

Keyboard shortcuts

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