kvo

package
v0.4.19 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

KVO models, records and storage

kvo defines logical models, typed properties, record views, editors, and Go bindings. A model can access encoded MessagePack/Fast2/Compact2 rows or native Go structs through the same API. Direct access and the Fastest decode-once hint are independent of storage format; see the access guide.

Declare typed properties through kvo.NewUnsignedProp, NewSignedProp, NewStringProp, NewTimeProp, NewListProp, and the corresponding map/record constructors. Model builders use one generic b.Prop(property, options...) method accepting typed references and schema declarations. Bare numeric codes do not compile; dynamic schemas resolve them with schema.MustPropByCode(code).

var Customer_Points = kvo.NewSignedProp[int64](schema, 18, "customer:points", kvo.TInt64)

// During model registration:
b.Prop(Customer_Points)

// During access/editing:
balance := customer.Get(Customer_Points) // int64
edit.Set(Customer_Points, balance + 10)

Use kvo.Model, Record, Editor, List[T] and Map[K,V]. MapOf and ListOf declare logical collection types. NewScalarProp accepts a custom values.Codec[T]; NewProp declares an untyped schema property.

Reuse canonical numeric types (TInt64, TUint32, TFloat64, etc.) for ordinary Go fields. Use named scalar types for domain semantics. TUintptr supports native and Fast2/Compact2 access; Go MessagePack does not encode uintptr fields. NewTimeProp preserves nanosecond timestamps; NewLegacyTimeProp preserves the older offset-microsecond encoding.

Use .Code() in raw codec/dynamic analytics loops. Resolve typed references at setup with CodeOf where an API needs a number.

Packages

Package Responsibility
kvo Models, typed properties, record and collection views, editors, Go bindings and their generator
values Shared cells, types, shapes and scalar conversions
nativebind Shared reflected and generated Go field access
kvo/codec/fast1 Original word-map encoding, borrowed views and mutable edits
kvo/codec/msgpack Borrowed MessagePack views, copy-on-write edits, pooled struct encoder/decoder
kvo/codec/row2 Shared Fast2/Compact2 wire format, views, writers and edits
edb Tables, transactions, row envelopes, indexes and storage migration

MessagePack and Fast1 have the same status: supported legacy formats that we intend to transition away from. Fast2 and Compact2 are the current formats. There is no automatic migration. Existing KVTable data remains Fast1, and ordinary Go tables remain MessagePack unless explicitly configured otherwise.

Fast2 and Compact2 belong in one package: they share scalar semantics and container framing, and a Fast2 row can contain Compact2 children. Layout hints such as kvo.Compact remain supported schema metadata; they describe storage, not different logical property types. Borrowed views remain transaction-scoped.

The low-level row2 writer uses its Fast2 and Compact2 layout constants. Pass the model after the name in edb.DefineTable. Inside its callback, select a named edb.StorageFormat:

b.SetRecordStorage(edb.RecordStorage{
    Format: edb.Fast2, // or edb.Compact2
})

RecordStorage requires Fast2 or Compact2 explicitly. For property access on existing MessagePack rows, pass the model and omit SetRecordStorage. Set MessagePackInserts: true on RecordStorage during a reader-first rollout. Existing MessagePack keys remain MessagePack until UpgradeRecord converts them; ordinary Put does not silently migrate those keys. All readers must support the new format before enabling its writes. The format names do not change existing wire tags, row-envelope versions, bucket names or memento bytes.

Source migration

Previous API Current API
kvo.ImmutableRecord, MutableRecord, ImmutableMap, MutableMap, Packable Same names under fast1
kvo.LoadRecord, LoadRecordData, NewRecord, UpdateRecord Same names under fast1
kvo/kvrow (kvrow) kvo/codec/row2 (row2)
kvo/kvbind (kvbind), kvo/record (record), kvo/model (model) kvo
kvo.Map(keyType, valueType) kvo.MapOf(keyType, valueType)
record.NewProp[T](...) kvo.NewScalarProp[T](...)
KVOAccess, SetKVOAccess, RecordAccess, SetRecordAccess Model argument to DefineTable(schema, name, model, configure)
KVOStorage, SetKVO RecordStorage, SetRecordStorage
KVOStorage{Fast: true} RecordStorage{Format: edb.Fast2}
KVOStorage{Fast: false} or omitted Fast RecordStorage{Format: edb.Compact2}

Regenerate Go bindings after updating imports. The old kvo/model and kvo/record paths are removed, including their aliases and forwarding functions. The source move leaves storage bytes, record sizes, and the Fast1 KVTable API unchanged.

Research history

research/kvo/draft is a historical candidate, not the current codec. The selected research design was promoted into kvo/codec/row2; the independent research writer still checks its bytes. Historical measurements and draft names remain in research reports. They do not describe current API status.

Documentation

Overview

Package kvo defines logical models, typed properties, and record access and editing over MessagePack, Fast2, Compact2, native Go structs, and decoded memory. Records and collection views use 16-byte handles. Storage codecs live in the codec subpackages; values supplies the shared value representation.

Fastest materializes the native binding when attached, or indexed memory otherwise, independently of the storage format. Fast keeps an existing Fast2 view and otherwise uses Fastest.

Package record binds registered Go structs to persistent KVO property codes.

Index

Constants

View Source
const RuntimePropBase uint64 = 1 << 63

RuntimePropBase reserves the upper half of the property namespace for runtime fields.

View Source
const TimeOffsetMicros = 62_135_596_800_000_000

TimeOffsetMicros is offset to Time.UnixMicro() that kvo stores, chosen such that time.Time{}.UnixMicro() = -TimeOffsetMicros. With this offset, 0 micros correspond to zero time instead of Unix epoch, and we can treat all times as unsigned integers.

Variables

View Source
var (
	TInt = NewIntType[int]("int", func(fc *FmtContext, v int) string {
		return strconv.FormatInt(int64(v), 10)
	})
	TInt8 = NewIntType[int8]("int8", func(fc *FmtContext, v int8) string {
		return strconv.FormatInt(int64(v), 10)
	})
	TInt16 = NewIntType[int16]("int16", func(fc *FmtContext, v int16) string {
		return strconv.FormatInt(int64(v), 10)
	})
	TInt32 = NewIntType[int32]("int32", func(fc *FmtContext, v int32) string {
		return strconv.FormatInt(int64(v), 10)
	})
	TInt64 = NewIntType[int64]("int64", func(fc *FmtContext, v int64) string {
		return strconv.FormatInt(v, 10)
	})
	TUint = NewIntType[uint]("uint", func(fc *FmtContext, v uint) string {
		return strconv.FormatUint(uint64(v), 10)
	})
	TUint8 = NewIntType[uint8]("uint8", func(fc *FmtContext, v uint8) string {
		return strconv.FormatUint(uint64(v), 10)
	})
	TUint16 = NewIntType[uint16]("uint16", func(fc *FmtContext, v uint16) string {
		return strconv.FormatUint(uint64(v), 10)
	})
	TUint32 = NewIntType[uint32]("uint32", func(fc *FmtContext, v uint32) string {
		return strconv.FormatUint(uint64(v), 10)
	})
	TUint64 = NewIntType[uint64]("uint64", func(fc *FmtContext, v uint64) string {
		return strconv.FormatUint(v, 10)
	})
	TUintptr = NewIntType[uintptr]("uintptr", func(fc *FmtContext, v uintptr) string {
		return strconv.FormatUint(uint64(v), 10)
	})
	TFloat32 = NewFloatType[float32]("float32", func(fc *FmtContext, v float32) string {
		return strconv.FormatFloat(float64(v), 'g', -1, 32)
	})
	TFloat64 = NewFloatType[float64]("float64", func(fc *FmtContext, v float64) string {
		return strconv.FormatFloat(v, 'g', -1, 64)
	})
	TUint64Hex = NewIntType[uint64]("uint64_hex", func(fc *FmtContext, v uint64) string {
		return "0x" + strconv.FormatUint(v, 16)
	})
	TUnknownUint64 = NewIntType[uint64]("unknown_uint64", func(fc *FmtContext, v uint64) string {
		return strconv.FormatUint(v, 10)
	})
	TUknownKey = NewIntType[uint64]("unknown_key", func(fc *FmtContext, v uint64) string {
		return "0x" + strconv.FormatUint(v, 16)
	})

	TTime = NewScalarType[time.Time]("time", func(fc *FmtContext, v uint64) string {
		return Uint64ToTime(v).Format(time.RFC3339)
	}, func(newValue, oldValue uint64) uint64 {
		return uint64(int64(newValue) - int64(oldValue))
	}, func(value, delta uint64) uint64 {
		return uint64(int64(value) + int64(delta))
	}, func(delta uint64) int {
		return sign(int64(delta))
	})

	TBool = NewScalarType[bool]("bool", func(fc *FmtContext, v uint64) string {
		switch v {
		case 0:
			return "false"
		case 1:
			return "true"
		default:
			return fmt.Sprintf("?bool(0x%x)", v)
		}
	}, nil, nil, nil)

	TMachineString = NewMachineStringType[string]("string")
)
View Source
var ErrNativeMapping = errors.New("kvo: invalid native mapping")

ErrNativeMapping identifies an invalid native declaration or an unregistered projection. Such errors are programmer errors and panic during setup.

View Source
var ErrOmittedEntry = errors.New("zero map entry requires KeepDictionaryZeroValues")
View Source
var ErrPropOption = errors.New("kvo: invalid property option")

ErrPropOption identifies an invalid property option, a schema declaration error.

View Source
var TBytes = NewBytesType[[]byte]("bytes")
View Source
var TJSON = &JSONType{&ScalarDataType{name: "json", codeSet: allocateTypeCode(), nativeType: reflect.TypeFor[any]()}}
View Source
var TTimestamp = &ScalarDataType{nativeType: reflect.TypeFor[time.Time](), name: "timestamp", codeSet: allocateTypeCode()}

TTimestamp preserves nanosecond precision over the full time.Time range. Current codecs store integers; TTime retains its legacy microsecond format.

Functions

func DecodeJSON added in v0.4.13

func DecodeJSON(v values.Value, dst any)

func Encoding added in v0.4.13

func Encoding(t AnyType) row2.Encoding

Encoding describes a property's wire conversion, independently of its runtime carrier. Containers remain explicit encoded byte spans; Child navigates them.

func Hex added in v0.3.3

func Hex(v uint64) string

func JSONValue added in v0.4.13

func JSONValue(v any) values.Value

JSONValue and DecodeJSON implement TJSON for reflective and generated bindings. Integer JSON tokens retain all 64 bits when decoded into an interface.

func LegacyTimeCodec added in v0.4.13

func LegacyTimeCodec() values.Codec[time.Time]

LegacyTimeCodec preserves TTime's offset-microsecond word representation. New persistent timestamps should use NewTimeProp and TTimestamp instead.

func RegisterMessagePackScalar added in v0.4.13

func RegisterMessagePackScalar(t reflect.Type, decode func(msgpack.View) values.Value)

RegisterMessagePackScalar supplies direct access for a Go scalar with custom MessagePack decoding. Register during initialization, before compiling any binding/projection of this type. The function must match the Go decoder, including historical encodings and nil, and must not mutate borrowed bytes. It returns the same normalized values.Value as Get. Encoding and editing continue to use the Go type's normal MessagePack encoder.

func SameType added in v0.4.13

func SameType(a, b AnyType) bool

SameType compares logical identity, including the key and value types of separately constructed map/list declarations.

func TimeToUint64 added in v0.3.1

func TimeToUint64(t time.Time) uint64

func Timestamp added in v0.4.13

func Timestamp(t time.Time) values.Value

func Type

func Type(model *Model) *values.Type

Type is the logical record identity, shared by all physical representations.

func Uint64ToTime added in v0.3.1

func Uint64ToTime(u uint64) time.Time

func WriteOptions added in v0.4.13

func WriteOptions(flags PropFlag) row2.KeyAccessOptions

WriteOptions converts model property flags to the options required by FastSetPathValue. Compilers can resolve these once when linking a field access.

Types

type AnyScalarType added in v0.3.4

type AnyScalarType interface {
	AnyType
}

type AnyType

type AnyType interface {
	Name() string
	String() string
	ValueKind() ValueKind
	Model() *Model
	ItemType() AnyType
	MapKeyType() AnyType
	MapProp(key uint64) PropImpl
	MapValueType(key uint64) AnyType
	Schema() *Schema // can return nil for generic types
	FormatValue(fc *FmtContext, value uint64) string
	Sub(lhs, rhs uint64) uint64
	Add(lhs, rhs uint64) uint64
	Sign(v uint64) int
	// contains filtered or unexported methods
}

type Binding added in v0.4.13

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

Binding is immutable schema metadata, reusable across transactions and programs. Retain configured bindings: using one publishes permanent representation IDs, never per-record or per-transaction metadata.

func Bind added in v0.4.13

func Bind(t reflect.Type, model *Model) *Binding

Bind returns the shared default binding for a Go struct and logical model. Configure generated/native access once and reuse the returned binding.

func (*Binding) Decode added in v0.4.13

func (b *Binding) Decode(raw []byte, dst reflect.Value)

Decode panics on error. Use TryDecode to handle errors explicitly.

func (*Binding) DecodeProperty added in v0.4.13

func (b *Binding) DecodeProperty(dst reflect.Value, r Record, key uint64)

DecodeProperty panics on error. Use TryDecodeProperty to handle errors explicitly.

func (*Binding) DirectMessagePack added in v0.4.13

func (b *Binding) DirectMessagePack() bool

func (*Binding) Encode added in v0.4.13

func (b *Binding) Encode(dst []byte, row reflect.Value, layout row2.Layout) []byte

func (*Binding) Encoded added in v0.4.13

func (b *Binding) Encoded(v row2.View) Record

func (*Binding) Generate added in v0.4.13

func (b *Binding) Generate(pkg, name string) []byte

Generate panics on error. Use TryGenerate to handle errors explicitly.

func (*Binding) MessagePack added in v0.4.13

func (b *Binding) MessagePack(raw []byte) Record

func (*Binding) NativeFieldIndex added in v0.4.13

func (b *Binding) NativeFieldIndex(key uint64) int

NativeFieldIndex resolves a direct Go field at table setup. It returns -1 for a property inside an inlined struct, which cannot be the table key field.

func (*Binding) Record added in v0.4.13

func (b *Binding) Record(ptr reflect.Value) Record

func (*Binding) TryDecode added in v0.4.13

func (b *Binding) TryDecode(raw []byte, dst reflect.Value) (err error)

TryDecode materializes owned Go values. Validation follows the model into each child.

func (*Binding) TryDecodeProperty added in v0.4.13

func (b *Binding) TryDecodeProperty(dst reflect.Value, r Record, key uint64) error

TryDecodeProperty decodes one modeled property into an addressable Go value using the shared native binding. It does not decode the rest of the record.

func (*Binding) TryEncode added in v0.4.13

func (b *Binding) TryEncode(dst []byte, row reflect.Value, layout row2.Layout) (out []byte, err error)

TryEncode reports data that the declared storage policies cannot represent.

func (*Binding) TryGenerate added in v0.4.13

func (b *Binding) TryGenerate(pkg, name string) ([]byte, error)

TryGenerate emits a binding in the row's own package. The caller writes the returned Go file during go generate and passes its variable to RecordStorage.

func (*Binding) TryValidate added in v0.4.13

func (b *Binding) TryValidate(raw []byte) (err error)

TryValidate checks that Decode can materialize a row without allocating the Go graph. Packed writers use this before publishing bytes supplied by a caller.

func (*Binding) Validate added in v0.4.13

func (b *Binding) Validate(raw []byte)

Validate panics on error. Use TryValidate to handle errors explicitly.

func (Binding) WithGenerated added in v0.4.13

func (b Binding) WithGenerated(g *Generated, mode nativebind.Mode) *Binding

func (Binding) WithNativeSchema added in v0.4.13

func (b Binding) WithNativeSchema(s NativeSchema) *Binding

type BoolPropRef added in v0.4.13

type BoolPropRef[T ~bool] struct {
	// contains filtered or unexported fields
}

func BindBoolProp added in v0.4.13

func BindBoolProp[T ~bool](schema *Schema, code uint64) BoolPropRef[T]

func NewBoolProp added in v0.4.13

func NewBoolProp[T ~bool](schema *Schema, code uint64, name string, typ AnyType) BoolPropRef[T]

func (BoolPropRef[T]) Code added in v0.4.13

func (p BoolPropRef[T]) Code() uint64

func (BoolPropRef[T]) Get added in v0.4.13

func (p BoolPropRef[T]) Get(r Record) T

func (BoolPropRef[T]) Set added in v0.4.13

func (p BoolPropRef[T]) Set(e *Editor, v T)

type BytesPropRef added in v0.4.13

type BytesPropRef[T ~[]byte] struct {
	// contains filtered or unexported fields
}

func BindBytesProp added in v0.4.13

func BindBytesProp[T ~[]byte](schema *Schema, code uint64) BytesPropRef[T]

func NewBytesProp added in v0.4.13

func NewBytesProp[T ~[]byte](schema *Schema, code uint64, name string, typ AnyType) BytesPropRef[T]

func (BytesPropRef[T]) Code added in v0.4.13

func (p BytesPropRef[T]) Code() uint64

func (BytesPropRef[T]) Get added in v0.4.13

func (p BytesPropRef[T]) Get(r Record) T

func (BytesPropRef[T]) Set added in v0.4.13

func (p BytesPropRef[T]) Set(e *Editor, v T)

type Cursor added in v0.4.13

type Cursor[T any] struct {
	// contains filtered or unexported fields
}

Cursor traverses a borrowed scalar collection once. Next does not repeat the record property lookup. Slice allocates a slice of the remaining values; strings and byte spans still borrow the source record's storage. A copied cursor has an independent traversal position.

func (Cursor[T]) Iter added in v0.4.13

func (it Cursor[T]) Iter() iter.Seq[T]

Iter returns a single-pass sequence over a copy of the current position. Breaking a range stops immediately; invoking that sequence again resumes it.

func (Cursor[T]) Len added in v0.4.13

func (it Cursor[T]) Len() int

func (*Cursor[T]) Next added in v0.4.13

func (it *Cursor[T]) Next() (T, bool)

func (Cursor[T]) OwnedSlice added in v0.4.13

func (it Cursor[T]) OwnedSlice() []T

OwnedSlice materializes the remaining elements and detaches their string or byte storage. Like Slice, it does not advance the original cursor.

func (Cursor[T]) Slice added in v0.4.13

func (it Cursor[T]) Slice() []T

type Editor added in v0.4.13

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

Editor applies property edits by path. A native editor writes to its bound struct.

func EditEncoded added in v0.4.13

func EditEncoded(e *row2.Editor) *Editor

EditEncoded shares an existing codec editor and writes through immediately. Use Record.Edit for a private editor that batches encoded changes.

func (*Editor) Changes added in v0.4.13

func (e *Editor) Changes() uint64

Changes counts assignments that changed a MessagePack or native record.

func (*Editor) Delete added in v0.4.13

func (e *Editor) Delete(p interface{ Code() uint64 })

Delete removes an encoded property or resets its native field to zero. Native fields without explicit presence cannot distinguish deletion from zero.

func (*Editor) Edit added in v0.4.13

func (e *Editor) Edit(p *PropRef[Record]) *Editor

Edit opens an attached child editor, or returns nil for an absent/null child. Merely opening an editor does not create or mutate the child.

func (*Editor) EditOrCreate added in v0.4.13

func (e *Editor) EditOrCreate(p *PropRef[Record]) *Editor

func (*Editor) FastSetPathValue added in v0.4.13

func (e *Editor) FastSetPathValue(path []row2.Step, x values.Value)

FastSetPathValue writes a path using its explicitly supplied Step.Options. EVM uses this API because its linker knows the model and precomputes these options once, avoiding model-policy lookups on every guest assignment. The options could be derived from the model, but doing so here would discard that optimization. They are used as-is, not merged with model defaults: callers must supply the intended compact-child and zero-preservation policy for each step. Explicit deletion also uses this path to bypass zero preservation. Ordinary property writes should use SetValue, which derives the policy. FastSetPathValue panics on error; use TryFastSetPathValue for error handling.

func (*Editor) FastSetPathValueWithWriter added in v0.4.13

func (e *Editor) FastSetPathValueWithWriter(path []row2.Step, x values.Value, w *row2.Writer)

FastSetPathValueWithWriter is FastSetPathValue with reusable encoding scratch.

func (*Editor) Get added in v0.4.13

func (e *Editor) Get[T any, P Property[T]](p P) T

func (*Editor) GetAs added in v0.4.13

func (e *Editor) GetAs(path []row2.Step, enc row2.Encoding) values.Value

GetAs and SetAs supply the leaf encoding for schema-free editors.

func (*Editor) GetPathValue added in v0.4.13

func (e *Editor) GetPathValue(path []row2.Step) values.Value

GetPathValue reads a nested property. Use GetValue for a direct property.

func (*Editor) GetValue added in v0.4.13

func (e *Editor) GetValue(key uint64) values.Value

GetValue reads one property, including pending edits.

func (*Editor) Has added in v0.4.13

func (e *Editor) Has(p interface{ Code() uint64 }) bool

Has reports the model's presence semantics, including pending changes.

func (*Editor) List added in v0.4.13

func (e *Editor) List[E any, P ListProperty[E]](p P) E

func (*Editor) Map added in v0.4.13

func (e *Editor) Map[K comparable, V any](p *MapPropRef[K, V]) *MapEditor[K, V]

func (*Editor) MessagePack added in v0.4.13

func (e *Editor) MessagePack() []byte

MessagePack returns the edited payload without re-encoding untouched fields. Nil means this editor has another backing representation.

func (*Editor) Model added in v0.4.13

func (e *Editor) Model() *Model

func (*Editor) NativeModel added in v0.4.13

func (e *Editor) NativeModel() *Model

func (*Editor) New added in v0.4.13

func (e *Editor) New(p *PropRef[Record]) *Editor

New explicitly creates an empty child. It panics if the child already exists.

func (*Editor) OwnsData added in v0.4.13

func (e *Editor) OwnsData() bool

func (*Editor) Packed added in v0.4.13

func (e *Editor) Packed() *row2.Editor

Packed exposes the codec editor. Direct codec writes bypass attached child editors, so obtaining it invalidates those child handles. Prefer Snapshot.

func (*Editor) Record added in v0.4.13

func (e *Editor) Record() Record

Record returns the current read view. Encoded edits produce a cached immutable snapshot; native edits still refer to their native object. Clone for isolation.

func (*Editor) Set added in v0.4.13

func (e *Editor) Set[T any, P Property[T]](p P, value T)

func (*Editor) SetAs added in v0.4.13

func (e *Editor) SetAs(path []row2.Step, x values.Value, enc row2.Encoding)

SetAs panics on error. Use TrySetAs to handle errors explicitly.

func (*Editor) SetValue added in v0.4.13

func (e *Editor) SetValue(key uint64, x values.Value)

SetValue writes one property using the model's write policy, including zero preservation for presence-significant and stored-primary-key properties. It panics on error; use TrySetValue to handle errors explicitly.

func (*Editor) Snapshot added in v0.4.13

func (e *Editor) Snapshot() row2.View

func (*Editor) TryFastSetPathValue added in v0.4.13

func (e *Editor) TryFastSetPathValue(path []row2.Step, x values.Value) error

TryFastSetPathValue is FastSetPathValue with explicit error handling.

func (*Editor) TryFastSetPathValueWithWriter added in v0.4.13

func (e *Editor) TryFastSetPathValueWithWriter(path []row2.Step, x values.Value, w *row2.Writer) (err error)

TryFastSetPathValueWithWriter is TryFastSetPathValue with reusable encoding scratch.

func (*Editor) TrySet added in v0.4.13

func (e *Editor) TrySet[T any, P Property[T]](p P, value T) (err error)

func (*Editor) TrySetAs added in v0.4.13

func (e *Editor) TrySetAs(path []row2.Step, x values.Value, enc row2.Encoding) (err error)

func (*Editor) TrySetValue added in v0.4.13

func (e *Editor) TrySetValue(key uint64, x values.Value) (err error)

TrySetValue is SetValue with explicit error handling.

func (*Editor) WithModel added in v0.4.13

func (e *Editor) WithModel(model *Model) *Editor

type EntityType added in v0.3.4

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

func NewEntityType

func NewEntityType(schema *Schema, name string, nativeTypes ...reflect.Type) *EntityType

func (*EntityType) Add added in v0.3.27

func (typ *EntityType) Add(lhs, rhs uint64) uint64

func (*EntityType) FormatValue added in v0.3.4

func (typ *EntityType) FormatValue(fc *FmtContext, value uint64) string

func (*EntityType) ItemType added in v0.3.4

func (typ *EntityType) ItemType() AnyType

func (*EntityType) MapKeyType added in v0.3.4

func (typ *EntityType) MapKeyType() AnyType

func (*EntityType) MapProp added in v0.3.4

func (typ *EntityType) MapProp(key uint64) PropImpl

func (*EntityType) MapValueType added in v0.3.4

func (typ *EntityType) MapValueType(key uint64) AnyType

func (*EntityType) Model added in v0.3.4

func (typ *EntityType) Model() *Model

func (*EntityType) Name added in v0.3.4

func (typ *EntityType) Name() string

func (*EntityType) NativeTypes added in v0.4.12

func (typ *EntityType) NativeTypes() []reflect.Type

NativeTypes returns the explicitly allowed struct projections for this type.

func (*EntityType) Schema added in v0.3.4

func (typ *EntityType) Schema() *Schema

func (*EntityType) Sign added in v0.3.27

func (typ *EntityType) Sign(v uint64) int

func (*EntityType) String added in v0.3.5

func (typ *EntityType) String() string

func (*EntityType) Sub added in v0.3.27

func (typ *EntityType) Sub(lhs, rhs uint64) uint64

func (*EntityType) ValueKind added in v0.3.4

func (typ *EntityType) ValueKind() ValueKind

type FieldMap added in v0.4.13

type FieldMap map[reflect.Type]map[PropCode]string

FieldMap associates exposed properties with direct, exported Go fields. A type without an entry uses its registered kvo tags (or legacy edb tags). Unmapped Go fields stay on the decoded row and do not become script properties.

type Float32PropRef added in v0.4.13

type Float32PropRef[T ~float32] struct {
	// contains filtered or unexported fields
}

func BindFloat32Prop added in v0.4.13

func BindFloat32Prop[T ~float32](schema *Schema, code uint64) Float32PropRef[T]

func NewFloat32Prop added in v0.4.13

func NewFloat32Prop[T ~float32](schema *Schema, code uint64, name string, typ AnyType) Float32PropRef[T]

func (Float32PropRef[T]) Code added in v0.4.13

func (p Float32PropRef[T]) Code() uint64

func (Float32PropRef[T]) Get added in v0.4.13

func (p Float32PropRef[T]) Get(r Record) T

func (Float32PropRef[T]) Set added in v0.4.13

func (p Float32PropRef[T]) Set(e *Editor, v T)

type Float64PropRef added in v0.4.13

type Float64PropRef[T ~float64] struct {
	// contains filtered or unexported fields
}

func BindFloat64Prop added in v0.4.13

func BindFloat64Prop[T ~float64](schema *Schema, code uint64) Float64PropRef[T]

func NewFloat64Prop added in v0.4.13

func NewFloat64Prop[T ~float64](schema *Schema, code uint64, name string, typ AnyType) Float64PropRef[T]

func (Float64PropRef[T]) Code added in v0.4.13

func (p Float64PropRef[T]) Code() uint64

func (Float64PropRef[T]) Get added in v0.4.13

func (p Float64PropRef[T]) Get(r Record) T

func (Float64PropRef[T]) Set added in v0.4.13

func (p Float64PropRef[T]) Set(e *Editor, v T)

type FloatValue

type FloatValue interface {
	~float32 | ~float64
}

type FmtContext added in v0.3.4

type FmtContext struct{}

type Generated added in v0.4.13

type Generated struct {
	Fields      map[reflect.Type]*nativebind.GeneratedFields
	Fingerprint string
	Encode      func([]byte, any, row2.Layout) []byte
	Decode      func([]byte, any)
}

Generated binds direct Go field operations to the exact registered model.

type IntegerStringer added in v0.3.4

type IntegerStringer interface {
	IntegerValue
	fmt.Stringer
}

type IntegerValue

type IntegerValue interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type JSONOptions added in v0.4.13

type JSONOptions struct {
	Context context.Context
	Charge  func(uint64) error
}

JSONOptions lets a host meter a detached JSON projection.

type JSONType added in v0.4.13

type JSONType struct{ *ScalarDataType }

JSONType holds a JSON value in a byte span. Missing and explicit null remain distinguishable through property presence or dictionary membership.

type LegacyTimePropRef added in v0.4.13

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

LegacyTimePropRef retains TTime's offset-microsecond word encoding.

func NewLegacyTimeProp added in v0.4.13

func NewLegacyTimeProp(schema *Schema, code uint64, name string) LegacyTimePropRef

func (LegacyTimePropRef) Code added in v0.4.13

func (p LegacyTimePropRef) Code() uint64

func (LegacyTimePropRef) FromWord added in v0.4.13

func (p LegacyTimePropRef) FromWord(v uint64) time.Time

func (LegacyTimePropRef) Get added in v0.4.13

func (p LegacyTimePropRef) Get(r Record) time.Time

func (LegacyTimePropRef) ToWord added in v0.4.13

func (p LegacyTimePropRef) ToWord(v time.Time) uint64

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List is a 16-byte borrowed collection view. Get resolves the property once; Cursor and Iter initialize independent, single-pass traversal positions. Keeping a List alive keeps its Go backing storage alive, but does not extend a database transaction's lifetime.

func (List[T]) Cursor added in v0.4.13

func (l List[T]) Cursor() Cursor[T]

func (List[T]) Iter added in v0.4.13

func (l List[T]) Iter() iter.Seq[T]

Iter returns a single-pass sequence. Reusing this sequence resumes its position; call Iter again to start a separate traversal.

func (List[T]) Len added in v0.4.13

func (l List[T]) Len() int

func (List[T]) Missing added in v0.4.13

func (l List[T]) Missing() bool

func (List[T]) OwnedSlice added in v0.4.13

func (l List[T]) OwnedSlice() []T

OwnedSlice copies both the slice and any borrowed string/byte elements.

func (List[T]) Slice added in v0.4.13

func (l List[T]) Slice() []T

func (List[T]) Value added in v0.4.13

func (l List[T]) Value() values.Value

type ListAccess added in v0.4.13

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

ListAccess is shared model metadata for reading a collection when its element type is supplied dynamically, as it is in EVM bytecode. It creates the same ListCell representation used by List[T] and RecordList.

func BindListAccess added in v0.4.13

func BindListAccess(model *Model, code uint64) *ListAccess

BindListAccess returns the model's cached accessor. Recompiling a script does not create immortal representation metadata per program or per invocation.

func (*ListAccess) Get added in v0.4.13

func (a *ListAccess) Get(r Record) ListCell

func (*ListAccess) TryCell added in v0.4.13

func (a *ListAccess) TryCell(v values.Value) (ListCell, bool)

TryCell also validates the declared element type before using a dynamically transported cell. It accepts cells made by typed Go property references.

type ListCell added in v0.4.13

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

ListCell is a typed cell pointing directly at borrowed storage. Its shared representation describes the encoding and element access; no per-list box is allocated. Traversal state is separate: local in Go or reused by the VM.

func ListCellFromValue added in v0.4.13

func ListCellFromValue(v values.Value) ListCell

func TryListCell added in v0.4.13

func TryListCell(v values.Value) (ListCell, bool)

TryListCell checks that v belongs to the collection representation registry. Record cells and ordinary bytes/slices are not interchangeable with list cells.

func (ListCell) At added in v0.4.13

func (l ListCell) At(index int) values.Value

func (ListCell) Iter added in v0.4.13

func (l ListCell) Iter() ListValueIterator

Iter builds local traversal state; the cell itself stays 16 bytes.

func (ListCell) Len added in v0.4.13

func (l ListCell) Len() int

func (ListCell) Value added in v0.4.13

func (l ListCell) Value() values.Value

Value transports a borrowed collection in one shared cell without boxing.

func (ListCell) View added in v0.4.13

func (l ListCell) View() ListValue

View expands a cell into stack access metadata. Retain the compact cell when passing a collection around; keep the expanded view beside a hot iterator.

type ListEditor added in v0.4.13

type ListEditor[T any] struct {
	// contains filtered or unexported fields
}

ListEditor materializes the selected list on its first mutation, then batches subsequent changes. It never decodes the enclosing record.

func (*ListEditor[T]) AddUnique added in v0.4.13

func (l *ListEditor[T]) AddUnique(v T) bool

func (*ListEditor[T]) Append added in v0.4.13

func (l *ListEditor[T]) Append(items ...T)

func (*ListEditor[T]) Clear added in v0.4.13

func (l *ListEditor[T]) Clear()

func (*ListEditor[T]) Contains added in v0.4.13

func (l *ListEditor[T]) Contains(v T) bool

func (*ListEditor[T]) Get added in v0.4.13

func (l *ListEditor[T]) Get(index int) T

func (*ListEditor[T]) Iter added in v0.4.13

func (l *ListEditor[T]) Iter() iter.Seq[T]

func (*ListEditor[T]) Len added in v0.4.13

func (l *ListEditor[T]) Len() int

func (*ListEditor[T]) Remove added in v0.4.13

func (l *ListEditor[T]) Remove(v T) bool

func (*ListEditor[T]) RemoveAt added in v0.4.13

func (l *ListEditor[T]) RemoveAt(index int)

func (*ListEditor[T]) Set added in v0.4.13

func (l *ListEditor[T]) Set(index int, v T)

func (*ListEditor[T]) Slice added in v0.4.13

func (l *ListEditor[T]) Slice() []T

type ListPropRef added in v0.4.13

type ListPropRef[T any] struct {
	*PropRef[List[T]]
	// contains filtered or unexported fields
}

ListPropRef shares conversion and representation metadata across all values.

func BindListProp added in v0.4.13

func BindListProp[T any](schema *Schema, code uint64, codec values.Codec[T]) *ListPropRef[T]

func NewListProp added in v0.4.13

func NewListProp[T any](schema *Schema, code uint64, name string, typ AnyType, codec values.Codec[T]) *ListPropRef[T]

func (*ListPropRef[T]) FromSlice added in v0.4.13

func (p *ListPropRef[T]) FromSlice(items []T) List[T]

FromSlice copies items into an owned encoded collection for assignment. Reads through Get do not make this copy.

func (*ListPropRef[T]) SetSlice added in v0.4.13

func (p *ListPropRef[T]) SetSlice(e *Editor, items []T)

type ListProperty added in v0.4.13

type ListProperty[E any] interface {
	// contains filtered or unexported methods
}

ListProperty selects a scalar or record list editor from its property type.

type ListType added in v0.4.12

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

ListType is schema metadata for positional values. The legacy Fast1 codec does not acquire List encoding support by declaring this type.

func ListOf added in v0.4.12

func ListOf(itemType AnyType) *ListType

func (*ListType) Add added in v0.4.12

func (typ *ListType) Add(uint64, uint64) uint64

func (*ListType) FormatValue added in v0.4.12

func (typ *ListType) FormatValue(*FmtContext, uint64) string

func (*ListType) ItemType added in v0.4.12

func (typ *ListType) ItemType() AnyType

func (*ListType) MapKeyType added in v0.4.12

func (typ *ListType) MapKeyType() AnyType

func (*ListType) MapProp added in v0.4.12

func (typ *ListType) MapProp(uint64) PropImpl

func (*ListType) MapValueType added in v0.4.12

func (typ *ListType) MapValueType(uint64) AnyType

func (*ListType) Model added in v0.4.12

func (typ *ListType) Model() *Model

func (*ListType) Name added in v0.4.12

func (typ *ListType) Name() string

func (*ListType) Schema added in v0.4.12

func (typ *ListType) Schema() *Schema

func (*ListType) Sign added in v0.4.12

func (typ *ListType) Sign(uint64) int

func (*ListType) String added in v0.4.12

func (typ *ListType) String() string

func (*ListType) Sub added in v0.4.12

func (typ *ListType) Sub(uint64, uint64) uint64

func (*ListType) ValueKind added in v0.4.12

func (typ *ListType) ValueKind() ValueKind

type ListValue added in v0.4.13

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

ListValue borrows a list property without constructing a slice or converting its encoding. Its lifetime is the source record's lifetime. Scalar and string elements are read without allocations; aggregate elements use GetValue's encoding.

func (ListValue) At added in v0.4.13

func (l ListValue) At(index int) values.Value

At reads one element; MessagePack and Compact2 require a linear scan. Prefer Iter for sequential access. The returned string/bytes may borrow source data.

func (ListValue) Iter added in v0.4.13

func (l ListValue) Iter() ListValueIterator

func (ListValue) Len added in v0.4.13

func (l ListValue) Len() int

func (ListValue) Missing added in v0.4.13

func (l ListValue) Missing() bool

type ListValueIterator added in v0.4.13

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

ListValueIterator visits scalar elements without allocating or rescanning earlier elements. Keep it as a local value; it borrows the list's source data.

func (*ListValueIterator) Next added in v0.4.13

func (it *ListValueIterator) Next() (values.Value, bool)

type LocalID added in v0.3.19

type LocalID uint64

type MachineStringType added in v0.3.32

type MachineStringType = ScalarDataType

func NewMachineStringType added in v0.3.32

func NewMachineStringType[T ~string](name string) *MachineStringType

type Map added in v0.3.4

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map is a 16-byte borrowed view. Lookup and iteration read the stored encoding; no Go map or intermediate encoding is constructed. Retain the owning Record with Own before retaining this view across a transaction boundary.

func (Map[K, V]) Get added in v0.4.13

func (m Map[K, V]) Get(key K) V

func (Map[K, V]) Iter added in v0.4.13

func (m Map[K, V]) Iter() iter.Seq2[K, V]

func (Map[K, V]) Keys added in v0.4.13

func (m Map[K, V]) Keys() iter.Seq[K]

Keys visits keys without decoding values, including dynamic JSON values.

func (Map[K, V]) Len added in v0.4.13

func (m Map[K, V]) Len() int

func (Map[K, V]) Lookup added in v0.4.13

func (m Map[K, V]) Lookup(key K) (out V, found bool)

func (Map[K, V]) Missing added in v0.4.13

func (m Map[K, V]) Missing() bool

type MapCodec added in v0.4.13

type MapCodec[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapCodec is reusable metadata for scalar, record, or nested-map values. Construct it during schema setup; views retain only their 16-byte cell.

func NewMapCodec added in v0.4.13

func NewMapCodec[K comparable, V any](typ *MapType, key values.Codec[K], value values.Codec[V]) *MapCodec[K, V]

func NewNestedMapCodec added in v0.4.13

func NewNestedMapCodec[K comparable, K2 comparable, V any](keyType AnyType, key values.Codec[K], inner *MapCodec[K2, V]) *MapCodec[K, Map[K2, V]]

NewNestedMapCodec builds an outer map whose values are borrowed typed maps.

func NewRecordMapCodec added in v0.4.13

func NewRecordMapCodec[K comparable](typ *MapType, key values.Codec[K]) *MapCodec[K, Record]

func (*MapCodec[K, V]) Prop added in v0.4.13

func (c *MapCodec[K, V]) Prop(schema *Schema, code uint64, name string, flags ...PropFlag) *MapPropRef[K, V]

Prop declares a typed map. Explicit flags replace the default zero-entry retention policy, allowing existing schemas to keep their storage contract.

func (*MapCodec[K, V]) Type added in v0.4.13

func (c *MapCodec[K, V]) Type() *MapType

type MapEditor added in v0.4.13

type MapEditor[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapEditor buffers entry changes. Reads observe the buffer immediately; encoded dictionaries and their parent records are rebuilt only on snapshot/save.

func EditMap added in v0.4.13

func EditMap[K comparable, K2 comparable, V any](outer *MapEditor[K, Map[K2, V]], key K) *MapEditor[K2, V]

EditMap opens an attached nested dictionary, returning nil for a missing key. The free function infers both maps' key/value types from the outer editor.

func EditOrCreateMap added in v0.4.13

func EditOrCreateMap[K comparable, K2 comparable, V any](outer *MapEditor[K, Map[K2, V]], key K) *MapEditor[K2, V]

func NewMap added in v0.4.13

func NewMap[K comparable, K2 comparable, V any](outer *MapEditor[K, Map[K2, V]], key K) *MapEditor[K2, V]

NewMap explicitly creates a nested dictionary. Existing entries panic.

func (*MapEditor[K, V]) Clear added in v0.4.13

func (m *MapEditor[K, V]) Clear()

Clear leaves an empty dictionary. Editor.Delete removes the property itself.

func (*MapEditor[K, V]) Delete added in v0.4.13

func (m *MapEditor[K, V]) Delete(key K) bool

func (*MapEditor[K, V]) Edit added in v0.4.13

func (m *MapEditor[K, V]) Edit(key K) *Editor

Edit opens a record-valued entry. Missing/null entries return nil; New and EditOrCreate explicitly create entries. Scalar-valued maps reject this API.

func (*MapEditor[K, V]) EditOrCreate added in v0.4.13

func (m *MapEditor[K, V]) EditOrCreate(key K) *Editor

func (*MapEditor[K, V]) Get added in v0.4.13

func (m *MapEditor[K, V]) Get(key K) V

func (*MapEditor[K, V]) Iter added in v0.4.13

func (m *MapEditor[K, V]) Iter() iter.Seq2[K, V]

func (*MapEditor[K, V]) Len added in v0.4.13

func (m *MapEditor[K, V]) Len() int

func (*MapEditor[K, V]) Lookup added in v0.4.13

func (m *MapEditor[K, V]) Lookup(key K) (V, bool)

func (*MapEditor[K, V]) New added in v0.4.13

func (m *MapEditor[K, V]) New(key K) *Editor

func (*MapEditor[K, V]) Set added in v0.4.13

func (m *MapEditor[K, V]) Set(key K, v V)

Set preserves zero values as present dictionary entries.

func (*MapEditor[K, V]) SetNull added in v0.4.13

func (m *MapEditor[K, V]) SetNull(key K)

SetNull stores an explicit null JSON entry. Lookup then returns (nil, true); Delete removes it. Non-JSON dictionaries reject null rather than silently zeroing.

type MapPropRef added in v0.4.13

type MapPropRef[K comparable, V any] struct {
	*PropRef[Map[K, V]]
	// contains filtered or unexported fields
}

func NewJSONMapProp added in v0.4.13

func NewJSONMapProp[K comparable](schema *Schema, code uint64, name string, keyType AnyType, key values.Codec[K]) *MapPropRef[K, any]

NewJSONMapProp borrows the dictionary and decodes only the selected dynamic entry. Scalar/record maps have allocation-free access; dynamic object trees allocate when materialized as any. Nil is a present JSON null, not deletion.

func NewMapProp added in v0.4.13

func NewMapProp[K comparable, V any](schema *Schema, code uint64, name string, typ *MapType, key values.Codec[K], value values.Codec[V]) *MapPropRef[K, V]

NewMapProp declares a typed scalar dictionary. Keys may be strings or integers, including domain enums; custom MessagePack key codecs retain their semantics.

func NewRecordMapProp added in v0.4.13

func NewRecordMapProp[K comparable](schema *Schema, code uint64, name string, typ *MapType, key values.Codec[K]) *MapPropRef[K, Record]

func (*MapPropRef[K, V]) Codec added in v0.4.13

func (p *MapPropRef[K, V]) Codec() *MapCodec[K, V]

func (*MapPropRef[K, V]) FromMap added in v0.4.13

func (p *MapPropRef[K, V]) FromMap(m map[K]V) Map[K, V]

FromMap creates an owned encoded dictionary for whole-property assignment. Ordinary borrowed reads and per-entry edits do not materialize this map.

type MapType added in v0.3.4

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

func MapOf added in v0.4.13

func MapOf(keyType AnyScalarType, itemType AnyType) *MapType

func (*MapType) Add added in v0.3.27

func (typ *MapType) Add(lhs, rhs uint64) uint64

func (*MapType) FormatValue added in v0.3.4

func (typ *MapType) FormatValue(fc *FmtContext, value uint64) string

func (*MapType) ItemType added in v0.3.4

func (typ *MapType) ItemType() AnyType

func (*MapType) MapKeyType added in v0.3.4

func (typ *MapType) MapKeyType() AnyType

func (*MapType) MapProp added in v0.3.4

func (typ *MapType) MapProp(key uint64) PropImpl

func (*MapType) MapValueType added in v0.3.4

func (typ *MapType) MapValueType(key uint64) AnyType

func (*MapType) Model added in v0.3.4

func (typ *MapType) Model() *Model

func (*MapType) Name added in v0.3.4

func (typ *MapType) Name() string

func (*MapType) Schema added in v0.3.4

func (typ *MapType) Schema() *Schema

func (*MapType) Sign added in v0.3.27

func (typ *MapType) Sign(v uint64) int

func (*MapType) String added in v0.3.5

func (typ *MapType) String() string

func (*MapType) Sub added in v0.3.27

func (typ *MapType) Sub(lhs, rhs uint64) uint64

func (*MapType) ValueKind added in v0.3.4

func (typ *MapType) ValueKind() ValueKind

type Model

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

func NewModel

func NewModel(schema *Schema, entityType *EntityType, build func(b *ModelBuilder)) *Model

func (*Model) AllProps added in v0.3.33

func (model *Model) AllProps() []PropImpl

func (*Model) MustPropByCode

func (model *Model) MustPropByCode(key uint64) PropImpl

func (*Model) Name

func (model *Model) Name() string

func (*Model) NativeStruct added in v0.4.12

func (model *Model) NativeStruct(t reflect.Type) *NativeStruct

NativeStruct resolves only an explicitly registered projection. Call after NewModel; tag validation occurs when that model is declared.

func (*Model) PrimaryKey added in v0.4.13

func (model *Model) PrimaryKey() PropImpl

PrimaryKey returns the explicitly stored key property, or nil for a model whose records do not carry database identity.

func (*Model) PropByCode added in v0.3.4

func (model *Model) PropByCode(key uint64) PropImpl

func (*Model) PropByName added in v0.3.24

func (model *Model) PropByName(name string) PropImpl

PropByName resolves every accepted property name: the model-local name, the original unqualified name, the full colon-qualified name, and its underscore spelling. Renaming a property locally preserves the other names.

func (*Model) PropBySelector added in v0.4.13

func (model *Model) PropBySelector(name string) PropImpl

PropBySelector resolves exactly the names enumerated by Selectors.

func (*Model) PropFlags added in v0.4.12

func (model *Model) PropFlags(key PropCode) PropFlag

PropFlags returns the model-specific options for a declared property.

func (*Model) RegisterNativeFields added in v0.4.13

func (model *Model) RegisterNativeFields(generated ...*nativebind.GeneratedFields)

RegisterNativeFields installs generated getters/setters for registered structs and their inline embeddings. Call after RegisterNativeType and before any binding or projection is built, including through a containing model. Missing types keep reflected access; supplied bindings must match exactly.

func (*Model) RegisterNativeType added in v0.4.13

func (model *Model) RegisterNativeType(t reflect.Type, fields ...map[PropCode]string)

RegisterNativeType attaches a Go struct after the logical model is declared. An omitted or nil field map uses kvo tags. An explicit map associates each model property with a direct exported Go field; other fields stay unexposed. Registration compiles and owns the mapping, so later map edits have no effect. Call during single-threaded setup, before constructing bindings or accessing records. Duplicate registrations panic.

func (*Model) Selectors added in v0.4.13

func (model *Model) Selectors() iter.Seq2[string, PropImpl]

Selectors enumerates the identifier-safe property names in lexical order. Each alias identifies the same model-specific property. Colon-qualified names remain available through PropByName and native mapping tags, not dot access.

func (*Model) Type added in v0.3.4

func (model *Model) Type() AnyType

type ModelBuilder

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

func (*ModelBuilder) Inline added in v0.4.13

func (b *ModelBuilder) Inline(model *Model)

Inline includes another model's properties directly, preserving names and storage policies. It adds no container property or wire nesting.

func (*ModelBuilder) Prop

func (b *ModelBuilder) Prop[P PropertyCode](property P, opts ...any)

Prop includes a typed property reference or a schema declaration. Numeric codes are not properties; resolve dynamic codes through Schema first.

type ModelDefinition

type ModelDefinition struct {
	Name  string
	Props []*PropInstance
}

type NativeField added in v0.4.12

type NativeField struct {
	Index                    int
	Path                     []int
	Prop                     PropImpl
	Compact                  bool
	PresenceIsSignificant    bool
	KeepDictionaryZeroValues bool
}

NativeField binds one explicit struct field to a property of its object model. Index addresses a direct field, or is -1 when Path traverses inlined structs.

func (NativeField) FieldPath added in v0.4.13

func (f NativeField) FieldPath() []int

FieldPath returns the complete Go field path, including explicit inline layers.

type NativeSchema added in v0.4.13

type NativeSchema interface {
	NativeFields(reflect.Type) *nativebind.Struct
	NativeType(reflect.Type) *values.Type
}

NativeSchema is implemented by evmbind.Schema. It connects a KVO projection to the same field operations and nominal type used by EVM host bindings.

type NativeStruct added in v0.4.12

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

NativeStruct is immutable, validated tag metadata. Persistent tables compile this metadata into a strict native conversion plan by Bind.

func (*NativeStruct) Fields added in v0.4.12

func (n *NativeStruct) Fields() []NativeField

Fields returns a copy, so a binding compiler cannot modify shared schema data.

func (*NativeStruct) Type added in v0.4.12

func (n *NativeStruct) Type() reflect.Type

type Optional added in v0.4.13

type Optional[T any] struct {
	Value   T
	Present bool
}

Optional is used only on properties marked PresenceIsSignificant. It adds no wire type: Present controls whether the ordinary value is stored at all.

type Projection added in v0.4.13

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

Projection binds properties to a Go struct or its MessagePack representation. It does not implement the row2 codec: the model may omit stored Go fields.

func Project added in v0.4.13

func Project(t reflect.Type, m *Model, fields FieldMap) *Projection

Project shares default projections (nil fields) by Go type and model. Explicit field maps create independent configurations; build those once and retain them, just like WithGenerated and WithNativeSchema configurations.

func (*Projection) DecodeProperty added in v0.4.13

func (p *Projection) DecodeProperty(dst reflect.Value, r Record, key uint64)

DecodeProperty panics on error. Use TryDecodeProperty to handle errors explicitly.

func (*Projection) DirectMessagePack added in v0.4.13

func (p *Projection) DirectMessagePack() bool

func (*Projection) HasNativeField added in v0.4.13

func (p *Projection) HasNativeField(index int) bool

HasNativeField reports whether a projection exposes a direct Go field index. EDB uses this once during registration to avoid decoding unexposed row keys.

func (*Projection) MessagePack added in v0.4.13

func (p *Projection) MessagePack(raw []byte) Record

func (*Projection) NativeFieldIndex added in v0.4.13

func (p *Projection) NativeFieldIndex(key uint64) int

func (*Projection) Record added in v0.4.13

func (p *Projection) Record(ptr reflect.Value) Record

func (*Projection) TryDecodeProperty added in v0.4.13

func (p *Projection) TryDecodeProperty(dst reflect.Value, r Record, key uint64) error

func (Projection) WithNativeSchema added in v0.4.13

func (p Projection) WithNativeSchema(s NativeSchema) *Projection

type Prop added in v0.3.4

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

func (*Prop) AnyType added in v0.3.4

func (p *Prop) AnyType() AnyType

func (*Prop) Code added in v0.3.4

func (p *Prop) Code() PropCode

func (*Prop) DefaultFlags added in v0.4.13

func (p *Prop) DefaultFlags() PropFlag

func (*Prop) FullName added in v0.4.13

func (p *Prop) FullName() string

func (*Prop) Name added in v0.3.4

func (p *Prop) Name() string

func (*Prop) TypeModel added in v0.3.4

func (p *Prop) TypeModel() *Model

func (*Prop) ValueKind added in v0.3.4

func (p *Prop) ValueKind() ValueKind

type PropBuilder

type PropBuilder struct{ Flags PropFlag }

PropBuilder supplies declaration defaults shared by every model using a property.

type PropCode

type PropCode = uint64

func CodeOf added in v0.4.13

func CodeOf(prop any) PropCode

CodeOf resolves a property reference at a schema/configuration boundary. Codec and dynamic-key loops should keep their numeric codes directly.

func NewProp

func NewProp(schema *Schema, code PropCode, name string, typ AnyType, build func(b *PropBuilder)) PropCode

type PropFlag

type PropFlag int
const (
	PropDense PropFlag = 1 << iota
	PropRequired
	// Compact selects Compact storage for this child and its descendants.
	Compact
	// PresenceIsSignificant keeps an explicitly stored zero distinct from absence.
	PresenceIsSignificant
	// KeepDictionaryZeroValues retains zero-valued entries in this dictionary.
	// It applies to string- and numeric-keyed Map properties, not to the
	// presence of the property itself or to nested dictionaries in its values.
	KeepDictionaryZeroValues
	// PrimaryKey declares an ordinary stored property as this model's database
	// key. It preserves explicit zero values; models may omit a key entirely.
	PrimaryKey
)

type PropImpl

type PropImpl interface {
	Name() string
	FullName() string
	Code() PropCode
	AnyType() AnyType
	TypeModel() *Model
	ValueKind() ValueKind
}

type PropInstance

type PropInstance struct {
	Flags    PropFlag
	Prop     PropImpl
	Dense    bool
	Required bool
	LocalID  LocalID
	// contains filtered or unexported fields
}

func (*PropInstance) PropInstance

func (pi *PropInstance) PropInstance() *PropInstance

type PropName added in v0.4.13

type PropName string

PropName gives a namespaced property its local field name on this model.

type PropOption

type PropOption interface {
	// contains filtered or unexported methods
}

type PropRef added in v0.4.13

type PropRef[T any] struct {
	// contains filtered or unexported fields
}

PropRef is a shared, typed access descriptor for one declared property. It is constructed once, never per record. Its result type can be a scalar or a borrowed view; it does not imply decoding the owning record.

func BindProp added in v0.4.13

func BindProp[T any](schema *Schema, code uint64, codec values.Codec[T]) *PropRef[T]

BindProp attaches reflection-free scalar conversion to an existing property. Type compatibility is checked here, never on the hot access path.

func BindRecordProp added in v0.4.13

func BindRecordProp(schema *Schema, code uint64) *PropRef[Record]

BindRecordProp returns child records as views, without decoding their structs.

func NewRecordProp added in v0.4.13

func NewRecordProp(schema *Schema, code uint64, name string, typ AnyType) *PropRef[Record]

func NewScalarProp added in v0.4.13

func NewScalarProp[T any](schema *Schema, code uint64, name string, typ AnyType, codec values.Codec[T]) *PropRef[T]

NewScalarProp declares a property and returns its typed access descriptor.

func (*PropRef[T]) Code added in v0.4.13

func (p *PropRef[T]) Code() uint64

func (*PropRef[T]) Get added in v0.4.13

func (p *PropRef[T]) Get(r Record) T

type Property added in v0.4.13

type Property[T any] interface {
	Code() uint64
	Get(Record) T
	// contains filtered or unexported methods
}

Property is implemented by typed codes and shared access descriptors. Generic methods keep the concrete property type; they do not box it.

type PropertyCode added in v0.4.13

type PropertyCode interface{ Code() PropCode }

PropertyCode is shared by typed property references and schema declarations.

type Record added in v0.4.13

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

Record is a 16-byte typed cell: a GC-visible data pointer plus a physical representation ID and byte length. Model and binding metadata are shared. Encoded views borrow their input; Own copies only when ownership is needed. A database primary key is available only when stored as a modeled property.

func Encoded added in v0.4.13

func Encoded(v row2.View) Record

func FromValue added in v0.4.13

func FromValue(v values.Value) Record

FromValue validates that a typed cell carries a registered KVO representation.

func TryFromValue added in v0.4.13

func TryFromValue(v values.Value) (Record, bool)

TryFromValue checks a cell's representation without interpreting its data.

func (Record) Child added in v0.4.13

func (r Record) Child(step row2.Step) Record

func (Record) Clone added in v0.4.13

func (r Record) Clone() Record

Clone returns an independent snapshot, including when the source already owns its storage. Encoded records keep their codec, binding, and unknown fields. Native records keep their Go type and copy their data graph, including fields outside the model. Maps, slices, pointers, interfaces, and strings are detached. Non-nil functions, channels, and unsafe pointers cannot be cloned and panic. No serialization or user codec is invoked for native objects.

Use Own for retention without an independent mutable snapshot. Fastest is an access hint and can retain an existing native or decoded object unchanged.

func (Record) Edit added in v0.4.13

func (r Record) Edit() *Editor

func (Record) Fast added in v0.4.13

func (r Record) Fast() Record

func (Record) Fastest added in v0.4.13

func (r Record) Fastest() Record

func (Record) Get added in v0.4.13

func (r Record) Get[T any, P Property[T]](p P) T

func (Record) GetAs added in v0.4.13

func (r Record) GetAs(key uint64, enc row2.Encoding) values.Value

func (Record) GetOwnedString added in v0.4.13

func (r Record) GetOwnedString(key uint64) values.Value

func (Record) GetValue added in v0.4.13

func (r Record) GetValue(key uint64) values.Value

func (Record) Has added in v0.4.13

func (r Record) Has(key uint64) bool

func (Record) ListValue added in v0.4.13

func (r Record) ListValue(key uint64) ListValue

ListValue returns a borrowed view of a modeled list property. Unlike GetValue, it does not materialize the list. Retain the record with Own before retaining its list beyond the source transaction. It panics for non-list properties.

func (Record) MessagePack added in v0.4.13

func (r Record) MessagePack() []byte

MessagePack returns the borrowed original payload, or nil for another representation. It preserves unmodeled fields without re-encoding.

func (Record) Missing added in v0.4.13

func (r Record) Missing() bool

func (Record) Model added in v0.4.13

func (r Record) Model() *Model

Model returns the logical model independently of native binding or encoding.

func (Record) Native added in v0.4.13

func (r Record) Native() any

func (Record) NativeModel added in v0.4.13

func (r Record) NativeModel() *Model

func (Record) NativeType added in v0.4.13

func (r Record) NativeType() *values.Type

func (Record) Own added in v0.4.13

func (r Record) Own() Record

Own returns a view independent of borrowed encoded storage. It copies the payload, including unknown properties, without decoding it. Already owned data is returned unchanged; this is not a deep clone of mutable Go objects.

func (Record) OwnsData added in v0.4.13

func (r Record) OwnsData() bool

func (Record) Snapshot added in v0.4.13

func (r Record) Snapshot() row2.View

func (Record) ToJSON added in v0.4.13

func (r Record) ToJSON(model *Model, options JSONOptions) map[string]any

ToJSON panics on error. Use TryToJSON to handle errors explicitly.

func (Record) TryToJSON added in v0.4.13

func (r Record) TryToJSON(model *Model, options JSONOptions) (out map[string]any, err error)

func (Record) Value added in v0.4.13

func (r Record) Value() values.Value

Value transports the record in the shared cell without boxing.

func (Record) WithModel added in v0.4.13

func (r Record) WithModel(m *Model) Record

type RecordCursor added in v0.4.13

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

RecordCursor traverses object elements without requiring their native Go struct type or decoding them. Each element carries its own model metadata.

func (RecordCursor) CloneSlice added in v0.4.13

func (c RecordCursor) CloneSlice() []Record

func (RecordCursor) Iter added in v0.4.13

func (c RecordCursor) Iter() iter.Seq[Record]

Iter returns a single-pass sequence over a copy of the current position.

func (RecordCursor) Len added in v0.4.13

func (c RecordCursor) Len() int

func (*RecordCursor) Next added in v0.4.13

func (c *RecordCursor) Next() (Record, bool)

func (RecordCursor) OwnedSlice added in v0.4.13

func (c RecordCursor) OwnedSlice() []Record

OwnedSlice retains each element with Own; native mutable objects may still be shared. Use CloneSlice for independent records, including native objects.

func (RecordCursor) Slice added in v0.4.13

func (c RecordCursor) Slice() []Record

type RecordList added in v0.4.13

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

RecordList is a 16-byte borrowed view of object elements. Each element carries its KVO model; no native Go struct type parameter is needed.

func (RecordList) CloneSlice added in v0.4.13

func (l RecordList) CloneSlice() []Record

func (RecordList) Cursor added in v0.4.13

func (l RecordList) Cursor() RecordCursor

func (RecordList) Iter added in v0.4.13

func (l RecordList) Iter() iter.Seq[Record]

Iter returns a single-pass sequence. Reusing this sequence resumes its position; call Iter again to start a separate traversal.

func (RecordList) Len added in v0.4.13

func (l RecordList) Len() int

func (RecordList) Missing added in v0.4.13

func (l RecordList) Missing() bool

func (RecordList) OwnedSlice added in v0.4.13

func (l RecordList) OwnedSlice() []Record

func (RecordList) Slice added in v0.4.13

func (l RecordList) Slice() []Record

func (RecordList) Value added in v0.4.13

func (l RecordList) Value() values.Value

type RecordListEditor added in v0.4.13

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

RecordListEditor keeps element editors attached until the list is replaced or structurally changed. Append/RemoveAt/Clear invalidate existing element editors.

func (*RecordListEditor) Append added in v0.4.13

func (l *RecordListEditor) Append(r Record)

func (*RecordListEditor) Clear added in v0.4.13

func (l *RecordListEditor) Clear()

func (*RecordListEditor) Edit added in v0.4.13

func (l *RecordListEditor) Edit(index int) *Editor

func (*RecordListEditor) Get added in v0.4.13

func (l *RecordListEditor) Get(index int) Record

func (*RecordListEditor) Iter added in v0.4.13

func (l *RecordListEditor) Iter() iter.Seq[Record]

func (*RecordListEditor) Len added in v0.4.13

func (l *RecordListEditor) Len() int

func (*RecordListEditor) New added in v0.4.13

func (l *RecordListEditor) New() *Editor

func (*RecordListEditor) RemoveAt added in v0.4.13

func (l *RecordListEditor) RemoveAt(index int)

type RecordListPropRef added in v0.4.13

type RecordListPropRef struct {
	*PropRef[RecordList]
	// contains filtered or unexported fields
}

func BindRecordListProp added in v0.4.13

func BindRecordListProp(schema *Schema, code uint64) *RecordListPropRef

func NewRecordListProp added in v0.4.13

func NewRecordListProp(schema *Schema, code uint64, name string, typ AnyType) *RecordListPropRef

type ScalarConverter

type ScalarConverter[T any] interface {
	ValueToScalar(value T) uint64
	ScalarToValue(scalar uint64) T
}

type ScalarDataType added in v0.4.12

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

ScalarDataType describes a string or byte slice; both are bounded byte spans.

func NewBytesType added in v0.4.12

func NewBytesType[T ~[]byte](name string) *ScalarDataType

NewBytesType declares binary data separately from text, without a new wire tag.

func (*ScalarDataType) Add added in v0.4.12

func (typ *ScalarDataType) Add(lhs, rhs uint64) uint64

func (*ScalarDataType) FormatValue added in v0.4.12

func (typ *ScalarDataType) FormatValue(fc *FmtContext, value uint64) string

func (*ScalarDataType) ItemType added in v0.4.12

func (typ *ScalarDataType) ItemType() AnyType

func (*ScalarDataType) MapKeyType added in v0.4.12

func (typ *ScalarDataType) MapKeyType() AnyType

func (*ScalarDataType) MapProp added in v0.4.12

func (typ *ScalarDataType) MapProp(key uint64) PropImpl

func (*ScalarDataType) MapValueType added in v0.4.12

func (typ *ScalarDataType) MapValueType(key uint64) AnyType

func (*ScalarDataType) Model added in v0.4.12

func (typ *ScalarDataType) Model() *Model

func (*ScalarDataType) Name added in v0.4.12

func (typ *ScalarDataType) Name() string

func (*ScalarDataType) NativeType added in v0.4.12

func (typ *ScalarDataType) NativeType() reflect.Type

func (*ScalarDataType) Schema added in v0.4.12

func (typ *ScalarDataType) Schema() *Schema

func (*ScalarDataType) Sign added in v0.4.12

func (typ *ScalarDataType) Sign(v uint64) int

func (*ScalarDataType) String added in v0.4.12

func (typ *ScalarDataType) String() string

func (*ScalarDataType) Sub added in v0.4.12

func (typ *ScalarDataType) Sub(lhs, rhs uint64) uint64

func (*ScalarDataType) ValueKind added in v0.4.12

func (typ *ScalarDataType) ValueKind() ValueKind

type Schema

type Schema struct {
	TPropCode AnyType
	// contains filtered or unexported fields
}

func NewSchema added in v0.3.4

func NewSchema() *Schema

func (*Schema) Models added in v0.4.13

func (schema *Schema) Models() []*Model

Models returns the schema's entity models in name order.

func (*Schema) MustPropByCode

func (schema *Schema) MustPropByCode(code PropCode) PropImpl

func (*Schema) PropByCode

func (schema *Schema) PropByCode(code PropCode) PropImpl

type SignedPropRef added in v0.4.13

type SignedPropRef[T values.Signed] struct {
	// contains filtered or unexported fields
}

func BindSignedProp added in v0.4.13

func BindSignedProp[T values.Signed](schema *Schema, code uint64) SignedPropRef[T]

func NewSignedProp added in v0.4.13

func NewSignedProp[T values.Signed](schema *Schema, code uint64, name string, typ AnyType) SignedPropRef[T]

func (SignedPropRef[T]) Code added in v0.4.13

func (p SignedPropRef[T]) Code() uint64

func (SignedPropRef[T]) Get added in v0.4.13

func (p SignedPropRef[T]) Get(r Record) T

func (SignedPropRef[T]) Set added in v0.4.13

func (p SignedPropRef[T]) Set(e *Editor, v T)

type StringPropRef added in v0.4.13

type StringPropRef[T ~string] struct {
	// contains filtered or unexported fields
}

func BindStringProp added in v0.4.13

func BindStringProp[T ~string](schema *Schema, code uint64) StringPropRef[T]

func NewStringProp added in v0.4.13

func NewStringProp[T ~string](schema *Schema, code uint64, name string, typ AnyType) StringPropRef[T]

func (StringPropRef[T]) Code added in v0.4.13

func (p StringPropRef[T]) Code() uint64

func (StringPropRef[T]) Get added in v0.4.13

func (p StringPropRef[T]) Get(r Record) T

func (StringPropRef[T]) Set added in v0.4.13

func (p StringPropRef[T]) Set(e *Editor, v T)

type TimePropRef added in v0.4.13

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

TimePropRef returns time.Time directly, without parsing or reflection.

func NewTimeProp added in v0.4.13

func NewTimeProp(schema *Schema, code uint64, name string) TimePropRef

func (TimePropRef) Code added in v0.4.13

func (p TimePropRef) Code() uint64

func (TimePropRef) Get added in v0.4.13

func (p TimePropRef) Get(r Record) time.Time

type UnsignedPropRef added in v0.4.13

type UnsignedPropRef[T values.Unsigned] struct {
	// contains filtered or unexported fields
}

func BindUnsignedProp added in v0.4.13

func BindUnsignedProp[T values.Unsigned](schema *Schema, code uint64) UnsignedPropRef[T]

func NewUnsignedProp added in v0.4.13

func NewUnsignedProp[T values.Unsigned](schema *Schema, code uint64, name string, typ AnyType) UnsignedPropRef[T]

func (UnsignedPropRef[T]) Code added in v0.4.13

func (p UnsignedPropRef[T]) Code() uint64

func (UnsignedPropRef[T]) Get added in v0.4.13

func (p UnsignedPropRef[T]) Get(r Record) T

func (UnsignedPropRef[T]) Set added in v0.4.13

func (p UnsignedPropRef[T]) Set(e *Editor, v T)

type ValueKind added in v0.3.4

type ValueKind int
const (
	ValueKindUnknown ValueKind = iota
	ValueKindWord
	ValueKindMap
	ValueKindScalarData
	ValueKindPIIData
	ValueKindList
)

type ValuePropRef added in v0.4.13

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

ValuePropRef keeps the shared carrier for properties whose access type is still an encoded aggregate or dynamic value. Typed collection traversal is available for lists; maps and arbitrary JSON retain their raw API semantics.

func BindValueProp added in v0.4.13

func BindValueProp(schema *Schema, code uint64) ValuePropRef

func NewValueProp added in v0.4.13

func NewValueProp(schema *Schema, code uint64, name string, typ AnyType) ValuePropRef

func (ValuePropRef) Code added in v0.4.13

func (p ValuePropRef) Code() uint64

func (ValuePropRef) Get added in v0.4.13

func (p ValuePropRef) Get(r Record) values.Value

type WordAdder added in v0.3.27

type WordAdder = func(lhs, rhs uint64) uint64

type WordFormatter added in v0.3.4

type WordFormatter = func(fc *FmtContext, v uint64) string

type WordSigner added in v0.3.27

type WordSigner = func(v uint64) int

type WordSubtractor added in v0.3.27

type WordSubtractor = func(lhs, rhs uint64) uint64

type WordType added in v0.3.4

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

func NewFloatType

func NewFloatType[T FloatValue](name string, formatter func(fc *FmtContext, v T) string) *WordType

func NewIntStringerType added in v0.3.4

func NewIntStringerType[T IntegerStringer](name string) *WordType

func NewIntType

func NewIntType[T IntegerValue](name string, formatter func(fc *FmtContext, v T) string) *WordType

func NewScalarSubtype

func NewScalarSubtype[T any](name string, base *WordType) *WordType

func NewScalarType

func NewScalarType[T any](name string, formatter WordFormatter, subtractor WordSubtractor, adder WordAdder, signer WordSigner) *WordType

func NewUnknownTypeWithErrorCode added in v0.3.5

func NewUnknownTypeWithErrorCode(errorCode string) *WordType

func (*WordType) Add added in v0.3.27

func (typ *WordType) Add(lhs, rhs uint64) uint64

func (*WordType) FormatValue added in v0.3.4

func (typ *WordType) FormatValue(fc *FmtContext, v uint64) string

func (*WordType) ItemType added in v0.3.4

func (typ *WordType) ItemType() AnyType

func (*WordType) MapKeyType added in v0.3.4

func (typ *WordType) MapKeyType() AnyType

func (*WordType) MapProp added in v0.3.4

func (typ *WordType) MapProp(key uint64) PropImpl

func (*WordType) MapValueType added in v0.3.4

func (typ *WordType) MapValueType(key uint64) AnyType

func (*WordType) Model added in v0.3.4

func (typ *WordType) Model() *Model

func (*WordType) MulInt added in v0.3.28

func (typ *WordType) MulInt(lhs uint64, rhs int64) uint64

func (*WordType) Name added in v0.3.4

func (typ *WordType) Name() string

func (*WordType) NativeType added in v0.4.12

func (typ *WordType) NativeType() reflect.Type

func (*WordType) Neg added in v0.3.28

func (typ *WordType) Neg(v uint64) uint64

func (*WordType) Schema added in v0.3.4

func (typ *WordType) Schema() *Schema

func (*WordType) Sign added in v0.3.27

func (typ *WordType) Sign(v uint64) int

func (*WordType) String added in v0.3.5

func (typ *WordType) String() string

func (*WordType) Sub added in v0.3.27

func (typ *WordType) Sub(lhs, rhs uint64) uint64

func (*WordType) ValueKind added in v0.3.4

func (typ *WordType) ValueKind() ValueKind

Directories

Path Synopsis
codec
fast1
Package fast1 implements the original KVO word-map storage format.
Package fast1 implements the original KVO word-map storage format.
msgpack
Package msgpack implements EDB's MessagePack struct encoding.
Package msgpack implements EDB's MessagePack struct encoding.
row2
Package row2 reads and writes the Fast2 and Compact2 KVO row formats.
Package row2 reads and writes the Fast2 and Compact2 KVO row formats.

Jump to

Keyboard shortcuts

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