dalgo2memory

package
v0.62.7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(options ...Option) dal.DB

NewDB creates an in-memory DALgo database.

func WithCollection

func WithCollection[T any](name string, newRecord func() *T, opts ...CollectionOption) collectionDef

WithCollection registers a collection backed by the concrete record type T.

If newRecord is nil, a zero value (new(T)) is used to materialize each record read by a query. Provide a factory to populate default field values instead.

Trailing CollectionOption arguments select a per-collection storage engine; with none, the collection uses the default Serialized engine.

Types

type CollectionOption

type CollectionOption func(*collectionDef)

CollectionOption configures a collection definition produced by WithCollection — currently the per-collection storage-engine selection. Pass it as a trailing argument to WithCollection.

func WithColumnarStorage

func WithColumnarStorage(opts ...ColumnOption) CollectionOption

WithColumnarStorage selects the columnar storage engine for a schema-registered WithCollection[T] collection, with optional per-column strategies and a per-collection ref-breaking override. Selecting columnar storage for a schemaless or non-struct collection fails with a descriptive error when the collection is used.

func WithSerializedStorage

func WithSerializedStorage() CollectionOption

WithSerializedStorage selects the Serialized storage engine for a collection. It is the default engine, so this option states the default explicitly; an option-less collection behaves identically.

type ColumnOption

type ColumnOption func(*columnarConfig)

ColumnOption configures a single aspect of a columnar collection: it either supplies a ColumnStrategy for a named column (WithColumnStrategy) or sets the per-collection ref-breaking override (WithColumnarRefBreaking). It is passed to WithColumnarStorage. Exported so an out-of-core package can return one carrying its own ColumnStrategy without dalgo2memory importing it.

func WithColumnStrategy

func WithColumnStrategy(name string, strategy ColumnStrategy) ColumnOption

WithColumnStrategy supplies a ColumnStrategy for the named column of a columnar collection. Columns without an explicit strategy use the default typed-slice strategy.

func WithColumnarRefBreaking

func WithColumnarRefBreaking(refBreaking bool) ColumnOption

WithColumnarRefBreaking sets the per-collection ref-breaking override for a columnar collection, taking precedence over the schema-wide default (WithoutSchemaRefBreaking). Pass true to force faithful storage, false to store reference-bearing columns without the serialization round-trip.

func WithDeclaredColumn

func WithDeclaredColumn[T any](name string) ColumnOption

WithDeclaredColumn declares a columnar column by name for a map-backed (map[string]any) collection, stored in a strongly-typed []T slice. At least one declared column is required to select columnar storage for a map-backed collection; undeclared fields are kept in a parallel leftover map. On a struct collection a declared column is accepted but redundant (the struct path reflects over the record type instead). When the same name is declared more than once, the last declaration wins.

type ColumnStrategy

type ColumnStrategy interface {
	// SetValue records that the column holds value at the given slot. The engine
	// calls it on every write (insert/overwrite/update) for the column.
	SetValue(slot int, value any)

	// ClearValue records that the slot no longer holds a value for the column.
	// The engine calls it on delete and during compaction rebuilds.
	ClearValue(slot int)

	// EqualSlots returns the live slots whose column equals value, with ok=true.
	// Returning ok=false signals "no opinion": the engine falls back to scanning.
	// Equality is the adapter's value equality (Go == on comparable decoded
	// values, as in matchesWhere).
	EqualSlots(value any) (slots SlotSet, ok bool)
}

ColumnStrategy backs a single column of a columnar collection. It is exported so an out-of-core package (e.g. a bitmap index) can supply a strategy via WithColumnStrategy without dalgo2memory importing it.

The engine remains the source of truth for stored values (its typed column slices); a strategy is an index kept in sync through the write side, used to accelerate the equality read side.

type Option

type Option func(*database)

Option configures an in-memory database created by NewDB.

func WithSchema

func WithSchema(allowUndefinedCollections bool, collections ...collectionDef) Option

WithSchema registers per-collection record types so that queries return records populated into the concrete Go type of the collection.

allowUndefinedCollections controls what happens when a query targets a collection that is not part of the schema: when false (the default intent) such a query returns an error; when true it falls back to the schemaless behavior (map[string]any / keys-only records).

func WithoutSchemaRefBreaking

func WithoutSchemaRefBreaking() Option

WithoutSchemaRefBreaking disables columnar ref-breaking schema-wide: columnar collections store reference-bearing column values without the serialization round-trip unless a collection re-enables it (see WithColumnarRefBreaking). It has no effect on the always-faithful Serialized engine. The default is faithful (ref-breaking on).

type SlotSet

type SlotSet map[int]struct{}

SlotSet is a set of per-row slot indices. The columnar engine assigns each live record a stable slot shared across all of a collection's column slices; a ColumnStrategy's equality read side returns the slots whose column equals a queried value. A set (rather than a slice) is returned so that, when the adapter grows multi-predicate AND WHERE, per-predicate sets can be intersected.

Jump to

Keyboard shortcuts

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