materializer

package
v0.53.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions added in v0.31.0

func ApplyOptions[T any](cfg *T, opts ...Option[T])

ApplyOptions applies each option in order to cfg.

Types

type ExportOption added in v0.31.0

type ExportOption = Option[ExportOptions]

ExportOption is a functional option for ExportOptions.

func WithColumnTypes added in v0.33.0

func WithColumnTypes(col *ingitdb.CollectionDef) ExportOption

WithColumnTypes populates ColumnTypes from a CollectionDef so that the INGR header includes type annotations for every column (e.g. "area_km2:int", "$ID:string").

func WithHash added in v0.31.0

func WithHash() ExportOption

WithHash enables the sha256 hash footer line in INGR output.

func WithRecordsDelimiter added in v0.31.0

func WithRecordsDelimiter() ExportOption

WithRecordsDelimiter enables a bare "#" delimiter line after each record in INGR output.

type ExportOptions added in v0.31.0

type ExportOptions struct {
	// IncludeHash appends a "# sha256:{hex}" line to the INGR footer.
	IncludeHash bool
	// RecordsDelimiter writes a bare "#" line after each record.
	RecordsDelimiter bool
	// ColumnTypes maps column names to their types for inclusion in the INGR header.
	// When set, each header column is written as "name:type" (e.g. "area_km2:int").
	// The "$ID" column key maps to the record key pseudo-column.
	ColumnTypes map[string]ingitdb.ColumnType
}

ExportOptions holds optional settings that modify INGR serialisation behaviour. Non-INGR formats ignore all fields.

type FileRecordsReader added in v0.13.1

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

FileRecordsReader loads records from collection files on disk.

func NewFileRecordsReader added in v0.13.1

func NewFileRecordsReader() FileRecordsReader

func (FileRecordsReader) ReadRecords added in v0.13.1

func (r FileRecordsReader) ReadRecords(
	ctx context.Context,
	dbPath string,
	col *ingitdb.CollectionDef,
	yield func(ingitdb.IRecordEntry) error,
) error

type FileViewDefReader added in v0.13.1

type FileViewDefReader struct{}

FileViewDefReader reads view definitions from .collection/views/*.yaml files.

func (FileViewDefReader) ReadViewDefs added in v0.13.1

func (FileViewDefReader) ReadViewDefs(colDirPath string) (map[string]*ingitdb.ViewDef, error)

type FileViewWriter added in v0.13.1

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

FileViewWriter renders a view template and writes it to a file.

func NewFileViewWriter added in v0.13.1

func NewFileViewWriter() FileViewWriter

func (FileViewWriter) WriteView added in v0.13.1

func (w FileViewWriter) WriteView(
	ctx context.Context,
	col *ingitdb.CollectionDef,
	view *ingitdb.ViewDef,
	records []ingitdb.IRecordEntry,
	outPath string,
) (WriteOutcome, error)

type FuncViewWriter added in v0.28.0

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

func NewFuncViewWriter added in v0.28.0

func NewFuncViewWriter(write func(content []byte) error) FuncViewWriter

func (FuncViewWriter) WriteView added in v0.28.0

func (w FuncViewWriter) WriteView(
	ctx context.Context,
	col *ingitdb.CollectionDef,
	view *ingitdb.ViewDef,
	records []ingitdb.IRecordEntry,
	outPath string,
) (WriteOutcome, error)

type IncrementalMaterializer

type IncrementalMaterializer interface {
	UpdateViews(
		ctx context.Context,
		dbPath string,
		def *ingitdb.Definition,
		affected []datavalidator.AffectedRecord,
	) (*ingitdb.MaterializeResult, error)
}

IncrementalMaterializer rebuilds only views affected by specific changed records.

type Option added in v0.31.0

type Option[T any] func(*T)

Option is a generic functional option that mutates a config struct T. Use with ApplyOptions to build a config from a variadic list of options.

Pipeline passing rules:

  • Exported functions that only forward options downstream: accept ...Option[T] (variadic).
  • Unexported functions where the options struct has more than one field and every field drives logic: accept T as a plain value. This avoids scattering individual parameters and keeps the signature compact.

type SimpleViewBuilder added in v0.13.1

type SimpleViewBuilder struct {
	DefReader     ViewDefReader
	RecordsReader ingitdb.RecordsReader
	Writer        ViewWriter
	Logf          func(format string, args ...any)
	// contains filtered or unexported fields
}

SimpleViewBuilder materializes view outputs using injected dependencies.

func NewViewBuilder added in v0.13.1

func NewViewBuilder(recordsReader ingitdb.RecordsReader, logf func(string, ...any)) SimpleViewBuilder

NewViewBuilder wires default view definition reader and file writer.

func (SimpleViewBuilder) BuildView added in v0.28.0

func (b SimpleViewBuilder) BuildView(
	ctx context.Context,
	dbPath string,
	repoRoot string,
	col *ingitdb.CollectionDef,
	def *ingitdb.Definition,
	view *ingitdb.ViewDef,
) (*ingitdb.MaterializeResult, error)

func (SimpleViewBuilder) BuildViews added in v0.13.1

func (b SimpleViewBuilder) BuildViews(
	ctx context.Context,
	dbPath string,
	repoRoot string,
	col *ingitdb.CollectionDef,
	def *ingitdb.Definition,
) (*ingitdb.MaterializeResult, error)

type ViewAffectedChecker

type ViewAffectedChecker interface {
	IsAffected(col *ingitdb.CollectionDef, view *ingitdb.ViewDef, changed []datavalidator.AffectedRecord) bool
}

ViewAffectedChecker determines whether a view needs rebuilding given changed records.

type ViewBuilder

type ViewBuilder interface {
	BuildViews(
		ctx context.Context,
		dbPath string,
		repoRoot string,
		col *ingitdb.CollectionDef,
		def *ingitdb.Definition,
	) (*ingitdb.MaterializeResult, error)
}

ViewBuilder orchestrates full materialisation of all views for one collection.

type ViewDefReader

type ViewDefReader interface {
	ReadViewDefs(colDirPath string) (map[string]*ingitdb.ViewDef, error)
}

ViewDefReader discovers and parses .ingitdb-view.*.yaml files.

type ViewRenderer

type ViewRenderer interface {
	RenderView(
		ctx context.Context,
		col *ingitdb.CollectionDef,
		view *ingitdb.ViewDef,
		reader ingitdb.RecordsReader,
		dbPath string,
	) (map[string][]byte, error) // key = format string ("md", "json")
}

ViewRenderer transforms records into rendered bytes per output format. Pure function; goroutine-safe.

type ViewWriter

type ViewWriter interface {
	WriteView(
		ctx context.Context,
		col *ingitdb.CollectionDef,
		view *ingitdb.ViewDef,
		records []ingitdb.IRecordEntry,
		outPath string,
	) (WriteOutcome, error)
}

ViewWriter renders a view and writes content to the file system. Separate from ViewBuilder so tests can capture output without I/O.

type WriteOutcome added in v0.29.0

type WriteOutcome int

WriteOutcome describes the result of a single view file write.

const (
	WriteOutcomeUnchanged WriteOutcome = iota
	WriteOutcomeCreated
	WriteOutcomeUpdated
)

Jump to

Keyboard shortcuts

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