collate

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package collate folds flat SQL rows into nested DTOs. It replaces the hand-written "seen map[ID]int" collapse idiom and the per-parent child-indexing maps used by the gather-and-merge read models in internal/queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collapse

func Collapse[Row any, K comparable, Parent any, Child any](
	rows []Row,
	key func(Row) K,
	newParent func(Row) Parent,
	child func(Row) (Child, bool),
	attach func(*Parent, Child),
) []Parent

Collapse folds parent×child rows (e.g. a LEFT JOIN result) into one parent per key, in first-seen order. newParent builds the parent from the first row seen for a key; child extracts that row's optional child (return ok=false to skip, e.g. a NULL join); attach appends the child to its parent.

func GroupByMap

func GroupByMap[T any, K comparable, V any](items []T, key func(T) K, val func(T) V) map[K][]V

GroupByMap indexes items by key, transforming each into a value — the side-query "xByGroup" pattern. Order within each slice follows input order.

func OrEmpty

func OrEmpty[T any](s []T) []T

OrEmpty returns a non-nil slice so JSON marshals to [] rather than null.

Types

This section is empty.

Jump to

Keyboard shortcuts

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