resultutil

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package resultutil contains small helpers for adapting tinySQL ResultSets to UI/API-friendly string matrices and compact result summaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResultSetToStringMatrix

func ResultSetToStringMatrix(rs *tinysql.ResultSet) ([]string, [][]string)

ResultSetToStringMatrix converts a tinySQL ResultSet to column names and string rows while preserving ResultSet column order.

func StringMatrixToResultSet

func StringMatrixToResultSet(columns []string, rows [][]string) *tinysql.ResultSet

StringMatrixToResultSet converts string rows back to a tinySQL ResultSet.

func ValueToString

func ValueToString(v any) string

ValueToString converts database values to display/API strings.

Types

type ColumnProfile

type ColumnProfile struct {
	Name      string       `json:"name"`
	NonEmpty  int          `json:"non_empty"`
	Nulls     int          `json:"nulls"`
	Distinct  int          `json:"distinct"`
	TopValues []ValueCount `json:"top_values,omitempty"`
	Numeric   bool         `json:"numeric"`
	Min       string       `json:"min,omitempty"`
	Max       string       `json:"max,omitempty"`
	Sum       string       `json:"sum,omitempty"`
	Avg       string       `json:"avg,omitempty"`
	Examples  []string     `json:"examples,omitempty"`
}

ColumnProfile describes one result column across all rows.

func ProfileColumns

func ProfileColumns(columns []string, rows [][]string, opts SummaryOptions) []ColumnProfile

ProfileColumns profiles string matrix columns across all supplied rows.

type Summary

type Summary struct {
	Columns    []string        `json:"columns,omitempty"`
	Rows       [][]string      `json:"rows,omitempty"`
	TotalRows  int             `json:"total_rows"`
	Summarized bool            `json:"summarized"`
	Profile    []ColumnProfile `json:"profile,omitempty"`
}

Summary is a compact, JSON-friendly representation of a query result.

func SummarizeMatrix

func SummarizeMatrix(columns []string, rows [][]string, opts SummaryOptions) *Summary

SummarizeMatrix returns raw rows when the result is small and a profiled, bounded sample when the result is too large to pass around in full.

func SummarizeResultSet

func SummarizeResultSet(rs *tinysql.ResultSet, opts SummaryOptions) *Summary

SummarizeResultSet summarizes a tinySQL ResultSet.

type SummaryOptions

type SummaryOptions struct {
	MaxRows      int
	MaxExamples  int
	MaxTopValues int
}

SummaryOptions controls how much raw data and profiling detail is included.

type ValueCount

type ValueCount struct {
	Value string `json:"value"`
	Count int    `json:"count"`
}

ValueCount is one value frequency entry in a ColumnProfile.

func TopValues

func TopValues(counts map[string]int, limit int) []ValueCount

TopValues returns the most common values, ordered by count desc then value asc.

Jump to

Keyboard shortcuts

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