output

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package output handles formatting and writing query results and errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintError

func PrintError(qerr *agenterrors.QueryError)

PrintError writes a classified error to stderr as JSON.

func PrintJSON

func PrintJSON(data any, prune bool)

PrintJSON writes a JSON object to stdout (for admin/schema output).

func PrintYAML added in v1.1.0

func PrintYAML(w io.Writer, data any) error

PrintYAML writes arbitrary data as YAML to the given writer.

func WriteError

func WriteError(w io.Writer, err error)

WriteError writes an error to stderr as JSON and sets the process exit code.

Types

type CSVWriter added in v1.1.0

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

CSVWriter streams rows as CSV. Column order is fixed at construction.

func NewCSVWriter added in v1.1.0

func NewCSVWriter(w io.Writer, columns []string) *CSVWriter

NewCSVWriter creates a new CSV writer with the given column order.

func (*CSVWriter) Flush added in v1.1.0

func (c *CSVWriter) Flush() error

func (*CSVWriter) WritePagination added in v1.1.0

func (c *CSVWriter) WritePagination(_ *Pagination) error

WritePagination is a no-op for CSV — no metadata support.

func (*CSVWriter) WriteRow added in v1.1.0

func (c *CSVWriter) WriteRow(row map[string]any) error

type Format

type Format string

Format identifies an output format.

const (
	FormatNDJSON Format = "jsonl"
	FormatJSON   Format = "json"
	FormatYAML   Format = "yaml"
	FormatCSV    Format = "csv"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses a format string, returning an error for unknown formats.

func ResolveFormat added in v1.1.0

func ResolveFormat(flagFormat string) Format

ResolveFormat resolves the output format from flag > config > default.

type JSONWriter added in v1.1.0

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

JSONWriter buffers all rows and writes a single JSON envelope on Flush.

func NewJSONWriter added in v1.1.0

func NewJSONWriter(w io.Writer, columns []string) *JSONWriter

NewJSONWriter creates a new JSON envelope writer. If columns is non-nil, it defines the column order; otherwise columns are extracted from the first row.

func (*JSONWriter) Flush added in v1.1.0

func (j *JSONWriter) Flush() error

func (*JSONWriter) WritePagination added in v1.1.0

func (j *JSONWriter) WritePagination(p *Pagination) error

func (*JSONWriter) WriteRow added in v1.1.0

func (j *JSONWriter) WriteRow(row map[string]any) error

type NDJSONWriter

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

NDJSONWriter writes query results as NDJSON (one JSON object per line).

func NewNDJSONWriter

func NewNDJSONWriter(w io.Writer) *NDJSONWriter

NewNDJSONWriter creates a new NDJSON result writer.

func (*NDJSONWriter) Flush

func (n *NDJSONWriter) Flush() error

func (*NDJSONWriter) WritePagination

func (n *NDJSONWriter) WritePagination(p *Pagination) error

func (*NDJSONWriter) WriteRow

func (n *NDJSONWriter) WriteRow(row map[string]any) error

type Pagination

type Pagination struct {
	HasMore  bool `json:"hasMore"`
	RowCount int  `json:"rowCount"`
}

Pagination holds pagination metadata for result sets.

type ResultWriter

type ResultWriter interface {
	WriteRow(row map[string]any) error
	WritePagination(p *Pagination) error
	Flush() error
}

ResultWriter writes query results in a streaming fashion.

func NewWriter added in v1.1.0

func NewWriter(w io.Writer, format Format, columns []string) ResultWriter

NewWriter creates a ResultWriter for the given format.

type YAMLWriter added in v1.1.0

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

YAMLWriter buffers all rows and writes YAML on Flush.

func NewYAMLWriter added in v1.1.0

func NewYAMLWriter(w io.Writer, columns []string) *YAMLWriter

NewYAMLWriter creates a new YAML writer. If columns is non-nil, it defines the column order; otherwise columns are extracted from the first row.

func (*YAMLWriter) Flush added in v1.1.0

func (y *YAMLWriter) Flush() error

func (*YAMLWriter) WritePagination added in v1.1.0

func (y *YAMLWriter) WritePagination(p *Pagination) error

func (*YAMLWriter) WriteRow added in v1.1.0

func (y *YAMLWriter) WriteRow(row map[string]any) error

Jump to

Keyboard shortcuts

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