data

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package data loads input records and coerces them to their declared types.

Coercion happens once, at load, which is what turns "19.99" into an exact decimal and "2005-05-24T22:53:30Z" into a time value, rather than making every expression do it.

Index

Constants

View Source
const DateLayout = "2006-01-02"

DateLayout is the accepted text form for a date parameter or member when the node gives no format.

Variables

This section is empty.

Functions

func Convert

func Convert(raw any, kind tmpl.ValueType, format string) (starlark.Value, error)

Convert coerces one value to a declared type.

The value may have come from JSON or straight from Go, since the library API takes records as maps or structs: a decimal.Decimal and a time.Time arrive as themselves rather than as text.

func FromStarlark

func FromStarlark(value starlark.Value) any

FromStarlark converts a value an expression produced back to the plain Go shape Record reads.

Anything without a plain equivalent -- a decimal, a time -- is passed through as itself, because Convert already accepts those.

func Generic

func Generic(raw any) starlark.Value

Generic converts a Go or JSON value with no declared type.

func MatchesType

func MatchesType(value starlark.Value, kind tmpl.ValueType) bool

MatchesType reports whether a value already has the declared type, which is what a defaultexpr result and a subreport arg must satisfy.

func ParamText

func ParamText(text string, kind tmpl.ValueType, format string) (starlark.Value, error)

ParamText parses a parameter value supplied as text — from the command line, or from a `default` — according to its declared type.

func ReadJSON

func ReadJSON(reader io.Reader) ([]map[string]any, error)

ReadJSON reads records from a JSON array document or from NDJSON, one record per line.

The whole dataset is buffered: DATA_COUNT, report-scoped aggregates, and keep-together lookahead all need the full sequence. NDJSON exists so that a large dataset is not one giant JSON value, not to enable streaming.

func Record

func Record(row map[string]any, decl *tmpl.Records, index int) (*expr.Record, error)

Record converts one row.

A member present in the data but not declared is not an error — data often carries members a report does not use. It is not reachable as a bare name, but it stays reachable as THIS["name"].

func Records

func Records(rows []map[string]any, decl *tmpl.Records) ([]*expr.Record, error)

Records converts loaded rows into the frozen records expressions see.

func Rows

func Rows(records any) ([]map[string]any, error)

Rows normalises the library API's input — a slice of maps, or of structs — into the map form the coercion path takes.

func Sequence

func Sequence(value starlark.Value) ([]map[string]any, error)

Sequence converts an expression's result into rows.

This is how a subreport reads the nested sequence its `data` names.

The elements arrive as Starlark values, already generic: a member declared type="list" holds whatever JSON put there, untyped. Turning them back into the plain Go shape a record is read from means the subreport's `records` coerces them exactly as a top-level `records` coerces the input file, rather than through a second path that could disagree with it.

func StructFields

func StructFields(value any) map[string]any

StructFields maps a struct's exported fields to member names, by an `sr` tag where one is given and by field name otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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