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
- func Convert(raw any, kind tmpl.ValueType, format string) (starlark.Value, error)
- func FromStarlark(value starlark.Value) any
- func Generic(raw any) starlark.Value
- func MatchesType(value starlark.Value, kind tmpl.ValueType) bool
- func ParamText(text string, kind tmpl.ValueType, format string) (starlark.Value, error)
- func ReadJSON(reader io.Reader) ([]map[string]any, error)
- func Record(row map[string]any, decl *tmpl.Records, index int) (*expr.Record, error)
- func Records(rows []map[string]any, decl *tmpl.Records) ([]*expr.Record, error)
- func Rows(records any) ([]map[string]any, error)
- func Sequence(value starlark.Value) ([]map[string]any, error)
- func StructFields(value any) map[string]any
Constants ¶
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 ¶
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 ¶
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 MatchesType ¶
MatchesType reports whether a value already has the declared type, which is what a defaultexpr result and a subreport arg must satisfy.
func ParamText ¶
ParamText parses a parameter value supplied as text — from the command line, or from a `default` — according to its declared type.
func ReadJSON ¶
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 ¶
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 Rows ¶
Rows normalises the library API's input — a slice of maps, or of structs — into the map form the coercion path takes.
func Sequence ¶
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 ¶
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.